5

I was using blank text files to run some tests, and was going crazy because FileUpload1.HasFile was always coming back false, even though it clearly had a file. I then switched test files to something above 0 kb (i.e. txt files with text in them), and then it worked.

As far as I can tell, you can't upload something of 0 kb. Is this true? I read about the FileUpload class on MSDN, but didn't notice anything that says files of 0 kb would be ignored/treated as not a file.

Realistically and practically, I don't see this as being much of a problem (why would you want to upload a blank file?), but I can imagine some kind of rare situation where I might want to reserve a space for something that doesn't have content yet, like a blank text file for a user to fill in when he/she has time.

CptSupermrkt
  • 6,844
  • 12
  • 56
  • 87
  • try this property `http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx` – Kris Ivanov May 24 '12 at 01:44

1 Answers1

5

you can use FileUpload.PostedFile Property, that will give you access to the file even if the content is 0 bytes

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35
  • Ah, I see. I was able to use if (FileUpload1.PostedFile != null) { article.Attachment1 = FileUpload1.PostedFile.FileName; } Thanks. – CptSupermrkt May 24 '12 at 01:49