本文介绍了传输生成的XML文件而不保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型Web表单应用程序,我想允许用户导出他们的数据,以防他们不想一次完成整个表单。然后当他们返回时,他们可以导入数据并继续他们离开的地方。

I have a large web form application that I want to allow the user to export their data in case they don't want to complete the entire form at once. Then when they return they can import the data and continue where they left off.

这是客户端要求的一部分,因为没有数据库是使用。

The reason for this is part of the requirement for the client is that no database is to be used.

我已经到了创建一个包含所有表单数据的XML文件,但我希望客户端能够下载该XML文件,而无需应用程序必须将其保存到服务器,甚至暂时保存。

I've gotten to the point where I create an XML file containing all the form data, but I want the client to be able to download that XML file without the application having to save it to the server, even temporarily.

是否可以创建XML文件并将其通过流/附件发送到客户端而不保存到磁盘?

Is it possible to create the XML file and transmit it via stream/attachment to the client without saving it to disk?

我正在使用C#Asp.net

I'm using C# Asp.net

推荐答案

您可以写入HttpResponse:

You can write to the HttpResponse:

        HttpResponse response = HttpContext.Current.Response;

        string xmlString = "<xml>blah</xml>";
        string fileName = "ExportedForm.xml";

        response.StatusCode = 200;

        response.AddHeader("content-disposition", "attachment; filename=" + fileName);
        response.AddHeader("Content-Transfer-Encoding", "binary");
        response.AddHeader("Content-Length", _Buffer.Length.ToString());

        response.ContentType = "application-download";
        response.Write(xmlString);

这篇关于传输生成的XML文件而不保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:31
查看更多