Hi

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

Thanks

Old post, probably not the only one but here is one i answered years ago. Example is C# but I'm sure you will figure it out ;)

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.