i am making an application in vb.net and i need help. The user will send me his issues or information through attachment. but i want a restriction on filesize that he can not attach file more then 20MB

i did some coding but its not working. it will show the size of file but not axectly the size in MB..

dim filesize=my.computer.filesystem.getfileinfo(textbox1.text)
msgbox filesize.length

now in above code it will show me the size of file in textbox1 but in bit like 1234567

i need it to show me in MB like 1MB or 10KB


1 Year
Discussion Span
Last Post by Minimalist

Philippe Thanks for the page but i am not that good in C# also i think that code is for Asp.net as per question. i need for vb.net


You need to apply some division to the file.length as this comes in bytes based on the charcters in your file. Here are some of the divisions:
info.Length / 1024 '= kilobytes
info.Length / 1048576 ' =megabytes
info.Length / 1073741824 '= gigabytes


thanks minimalist for suggestion it worked but it showing size in dots means when i attach file size 12,153Kb it giving me 11.8676071166992 MB

which i need to be 11.8MB only so how will do it...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.