简体   繁体   English

将文件传递到ASP.NET中的另一个项目

[英]Pass file to another project in ASP.NET

I'm trying to create simple app for editing .xml files. 我正在尝试创建用于编辑.xml文件的简单应用。 I have created another project within one solution to which I'm trying to pass file, where I would like to edit and save it. 我在一个尝试传递文件的解决方案中创建了另一个项目,我想在该文件中进行编辑和保存。 But is that possible? 但这有可能吗? I have tried to import System.web and then request HttpPostedFile as parameter of one function, but VS do not recognize such type there. 我试图导入System.web ,然后请求HttpPostedFile作为一个函数的参数,但是VS在那儿无法识别这种类型。 What am I doing wrong? 我究竟做错了什么?

尽管导入了System.Web,但无法识别HttpPostedFile

Alternatively, what is better way to pass file from one project to another? 另外,将文件从一个项目传递到另一个项目的更好方法是什么?

There are multiple ways to realize passing data between different classes. 有多种方法可以实现在不同类之间传递数据。

One way is to pass it with a Stream , as System.File.Open ( MSDN ) already gives back a FileStream . 一种方法是通过Stream传递它,因为System.File.OpenMSDN )已经返回了FileStream With streams you need to be careful with the handling of opening, closing, reading etc (see using ). 对于流,您需要注意打开,关闭,阅读等操作(请参阅使用 )。

Another way is by simply passing the path of the file as a string and open it elsewhere. 另一种方法是简单地将文件的路径作为字符串传递,然后在其他位置打开它。 But as you are trying to use a HttpPostedFile -object, I guess you're working on a project running on 2 different machines. 但是,当您尝试使用HttpPostedFile -object时,我想您正在一个在2台不同机器上运行的项目上工作。

You should read into streaming data, and with streaming it's irrelevant if you got the data from a file, a request or even another stream. 您应该读入流数据,而从文件,请求甚至另一个流中获取数据与流无关。

Edit: It seems your main first problem here was that the class HttpPostedFile was in a assembly you didnt referenced before. 编辑:看来您的主要首要问题是该类HttpPostedFile在您之前未引用的程序集中。 You can get tips for situations like these by pressing Ctrl + . 您可以通过按Ctrl +获得有关此类情况的提示. . VS suggests you things like creating a class for unknown objects or, if it's a common known object, adding references. VS建议您执行类似为未知对象创建类的操作,或者,如果它是常见的已知对象,则添加引用。

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

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