如何通过response.write在服务器上保存doc文件

时间:2016-02-18 13:38:42

标签: c# model-view-controller httpresponse

我的问题是这个代码在客户端下载docx(Response.write ..)但我想在specefic路径(在服务器中)下载它我该怎么办?

    private void htmlToDoc(string html)
    {
        Response.Clear();
        Response.Charset = "";
        Response.ContentType = "application/msword";


        string strFileName = "docName" + ".doc";
        Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);

        StringBuilder strHTMLContent = new StringBuilder();
        strHTMLContent.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:word\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head></head><body>");
        strHTMLContent.Append(html);
        strHTMLContent.Append("</body></html>");
        Response.Write(strHTMLContent);
        Response.End();
        Response.Flush();

     //   return strHTMLContent;
    }

1 个答案:

答案 0 :(得分:0)

出于安全原因,您无法指定客户端将文档下载到哪个路径。您可以做的唯一事情是准备文档类型并将其推送到客户端以提示下载,但浏览器将提示用户保存它的位置。

相关问题