.NET加载文件到HttpPostedFileBase [英] .NET load file to HttpPostedFileBase

查看:290
本文介绍了.NET加载文件到HttpPostedFileBase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以加载一个文件?我想要做的是这样的:

How can i load a file? i want to do something like this:

HttpPostedFileBase fileBase = File.Open(path, FileMode.Open);

然后我可以使用 fileBase.ContentType 和其他属性。

这可能吗?谢谢

推荐答案

您不能实例化这个类这样的(它是一个抽象类)。这样做的原因是这些信息诸如ContentType的是仅可与上载请求。

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.

所以,你可以存储的ContentType此刻的文件上传,并将其与数据存储中的文件关联。所以,你将有一个ID(上传文件的唯一identitifer),文件路径(该文件的物理存储位置)和contentType(该文件的内容类型)。这样,您就能够在以后检索的内容类型。

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.

这篇关于.NET加载文件到HttpPostedFileBase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆