Chris
Chris

Reputation: 8422

Detecting whether file was uploaded

Wondering whether there is there a nicer way to detect whether a file was actually uploaded than this?

if (Request.Files["ProfileImage"].InputStream.Length > 0)
{
    newCat.ProfileImage = SaveProfileImage();
}

In my web page there is a file control with name "ProfileImage"

<input type="file" name="ProfileImage" />

Upvotes: 3

Views: 171

Answers (1)

Jon Grant
Jon Grant

Reputation: 11530

You can just use the HttpPostedFile.ContentLength, but that's pretty much the same thing.

If you were using the <asp:FileUpload /> control, then you could access the HasFile property, but you're not :)

Upvotes: 2

Related Questions