简体   繁体   English

如何从HttpPostedFileBase对象创建FileInfo对象?

[英]How do I create a FileInfo object from an HttpPostedFileBase object?

I have a FileUpload control that passes the HttpPostedFileBase as a parameter into my controller. 我有一个FileUpload控件,它将HttpPostedFileBase作为参数传递到我的控制器中。 Currently in the controller, I save the HttpPostedFileBase, and get the full path by hard coding it. 当前在控制器中,我保存了HttpPostedFileBase,并通过对其进行硬编码来获取完整路径。 I need a way to simply access the HttpPostedFileBase from the FileUpload control, and turn it into a FileInfo object WITHOUT saving it. 我需要一种方法,可以从FileUpload控件中简单地访问HttpPostedFileBase,并将其转换为FileInfo对象而不保存它。 I apologize if this is a dumb question, but I am still struggling to grasp the concept and differences of all of the different type of HttpPostedFileBase/FileInfo/etc. 如果这是一个愚蠢的问题,我深表歉意,但我仍在努力理解HttpPostedFileBase / FileInfo / etc等所有不同类型的概念和差异。 file "things". 文件“东西”。 I'd appreciate anyone's help! 我会感谢任何人的帮助!

I made a comment about this and i decided to added as an answer. 我对此发表了评论,并决定添加为答案。

That's not possible. 那不可能 Fileinfo inherits from FileSystemInfo which can be a file or a directory(thats why DirectoryInfo exists). Fileinfo继承自FileSystemInfo ,后者可以是文件或目录(这就是DirectoryInfo存在的原因)。 So, its not possible to do it. 因此,不可能做到这一点。 You have to save the file in disk and load it with the path. 您必须将文件保存在磁盘中并使用路径加载。

FileInfo its not a Stream . FileInfo不是Stream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM