Click here to Skip to main content
14,550,695 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

How can I check the maximum size of a file? I tried this:

if (openDlg.FileName.Length <= 204800) {
    errorProvider.SetError(textBoxAttachFile, "Maxiumum XX MB");
}


Thanks in advance!
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Looks like you are checking the length of the file's name rather than its content; you probably need this[^].
   
Comments
Member 7762422 14-Apr-11 4:57am
   
Thanks Richard! I found myself another solution with your info!
   
@Member 7762422: I'm sorry but saying "I found myself another solution" you tell the lies. I hope this is just a mistake. But check again; and I think you owe Richard your apology.

Richard, you got 5.
--SA
Richard MacCutchan 15-Apr-11 4:27am
   
Thanks for your vote, and comments. However, this is no big deal and will happen from time to time.
   
Sure, not a big deal as this is most likely just a mistake. However, you are the one to be credited for this answer, just for the sake of truth.
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 4

If you want to check the content length of a file

Refer this:How to check file content length in asp:FileUpload?
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

Thanks Richard! I found myself another solution:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(openDlg.FileName);
this.textBoxAttachFile.Text = fileInfo.Length.ToString();
   
Comments
   
No! This is just the same.
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 3

You are checking the length of the file not the size of the file.
   
v2
Comments
Richard MacCutchan 14-Apr-11 5:36am
   
You may wish to reword this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100