[英]How to avoid downloading files to the download folder and download to other specific folder only in c#
I am trying to convert the gridview to excel and downloading the excel sheet to my computer's specific folder in my c# application. 我试图将gridview转换为excel,然后将excel工作表下载到c#应用程序中计算机的特定文件夹中。
The problem is: The file is getting downloaded at both the places.The destination folder and also the download folder. 问题是:文件在两个位置都被下载。目标文件夹和下载文件夹。
the code for this is: 该代码是:
private void ExportToExcel(GridView GrdView, string fname)
{
Response.Clear();
Response.AddHeader("content-disposition", "inline;filename=" + fname + ".xls");
Response.Charset = "";
Response.ContentType = "application/OCTET-STREAM";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
string renderedGridView = stringWrite.ToString();
File.WriteAllText(@"C:\\Users\abc\\Desktop\" + fname + ".xls", renderedGridView);
Response.Write(stringWrite.ToString());
Response.End();
}
How to avoid the files getting downloaded to the download folder? 如何避免文件下载到下载文件夹? Please help!
请帮忙! Thank you
谢谢
The answer would be to pick one: either render the control to a string and output to Response OR WriteAllText. 答案是选择一个:将控件呈现为字符串并输出到Response或WriteAllText。 If you want to use the WriteAllText to save the file to a determined location, then perform the action and pop up a notification to the user that the file was saved.
如果要使用WriteAllText将文件保存到确定的位置,请执行操作并弹出一条通知,通知用户文件已保存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.