0

I tried to get filename from uploaded file with WebImage like so:

var imageName = new WebImage(file.InputStream).FileName;

but FileName property always return null

maybe im missing something?

4 Answers 4

2

To get the filename of the Uploaded file, you can get the image from the request and then call this function on it.

var imageName = new WebImage(file.InputStream).FileName;

..would be

var image = WebImage.GetImageFromRequest().FileName;

This is the property for the image that was uploaded in the Request.

Sign up to request clarification or add additional context in comments.

Comments

1

I was looking through the source of the constructor you are using with Reflector and there is no place they set the file name.

But you can probably get the file name using

var fileName = Request.Files[0].FileName;

Its only this constructor that set the file name property:

public WebImage(string filePath) 
   : this(new HttpContextWrapper(HttpContext.Current), filePath) {}

and of course the private one it uses.

1 Comment

Request.Files[0].FileName will get full url to he file from my local disk: c:\images\image.jpg
1

I think the FileName property gets set only if you use the WebImage(String filename) constructor. You should be able to get the file name from file object. Other properties such as Height, Width, etc should work fine.

Comments

1

When you write new WebImage(file.InputStream), you're creating a WebImage object from a raw stream.
You never pass it anything with a name, so the FileName property is null.

You should use the file.FileName property from the HttpPostedFile object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.