Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 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

If you want to check the content length of a file

Refer this:How to check file content length in asp:FileUpload?
 
Share this answer
 
v2
You are checking the length of the file not the size of the file.
 
Share this answer
 
v2
Comments
Richard MacCutchan 14-Apr-11 5:36am    
You may wish to reword this.
Thanks Richard! I found myself another solution:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(openDlg.FileName);
this.textBoxAttachFile.Text = fileInfo.Length.ToString();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Apr-11 0:16am    
No! This is just the same.
--SA
Looks like you are checking the length of the file's name rather than its content; you probably need this[^].
 
Share this answer
 
Comments
Member 7762422 14-Apr-11 4:57am    
Thanks Richard! I found myself another solution with your info!
Sergey Alexandrovich Kryukov 15-Apr-11 0:15am    
@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.
Sergey Alexandrovich Kryukov 15-Apr-11 4:36am    
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900