开发者

asp.net mvc and FileName from WebImage

I tried to get filename from uplo开发者_如何学运维aded file with WebImage like so:

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

but FileName property always return null

maybe im missing something?


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜