Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在使用HttpContext导出excel时指定下载路径?_C#_Asp.net_Httpcontext - Fatal编程技术网

C# 如何在使用HttpContext导出excel时指定下载路径?

C# 如何在使用HttpContext导出excel时指定下载路径?,c#,asp.net,httpcontext,C#,Asp.net,Httpcontext,我已将表格数据导出到Excel。 我尝试了这段代码,但将其下载到默认的下载文件夹中。 我想把它下载到指定的路径。 如何指定给定的路径 HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-dispo

我已将表格数据导出到Excel。 我尝试了这段代码,但将其下载到默认的下载文件夹中。 我想把它下载到指定的路径。 如何指定给定的路径

            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ConsolidateRpt.xlsx");
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.ContentType = "application/excel";
            StringWriter writer = new StringWriter();
            HtmlTextWriter writer2 = new HtmlTextWriter(writer);           
            HttpContext.Current.Response.Write(writer.ToString());
            HttpContext.Current.Response.End();

服务器永远无法控制文件下载到客户端的位置。这也不可能。客户端控制下载文件在客户端驱动器上的位置


您只能指定文件名,这很好

实际位置取决于客户端,通常是浏览器。