.NET load file to HttpPostedFileBase
How can i load a file? i want to do something like this:
HttpPostedFileBase fileBase = File.Open(path, FileMode.Open)开发者_开发知识库;
then i could use fileBase.ContentType
and other properties.
is this possible? thanks
You cannot instantiate this class like this (it's an abstract class). The reason for this is that information such as ContentType was available only with the Upload request.
So you could store the ContentType at the moment the file is uploaded and associate it with the file in your data store. So you would have an Id (unique identitifer of of the uploaded file), FilePath (where the file is physically stored) and a ContentType (the content type of the file). This way you would be able to later retrieve the content type.
Not really - HttpPostedFile doesn't have constructors for such things. Plus I believe ContentType is determined and posted by the browser.
What are you trying to achieve?
HttpPostedFile postedFile = fileUpload1.PostedFile;
string mime = postefIle.ContentType;
if you are using c# and asp.net you can use cutewebui..along with ajax
Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader"
which is really professional and easy to work with.
精彩评论