Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Whats the best way to check the size of a file during upload using asp.net and C#? I can upload large files by altering my web.config without any problems. My issues arises when a file is uploaded which is more than my allowed max file size.

I have looked into using activex objects but that is not cross browser compatible and not the best answer to the solution. I need it to be cross browser compatible if possible and to support IE6 (i know what you are thinking!! However 80% of my apps users are IE6 and this is not going to change anytime soon unfortunately).

Has any dev out there come across the same problem? And if so how did you solve it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are using System.Web.UI.WebControls.FileUpload control:

MyFileUploadControl.PostedFile.ContentLength;

Returns the size of the posted file, in bytes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...