我如何下载物理path中的空Excel文件?
在这里,我想下载链接中的空Excel文件button单击物理path中的事件。 我的代码是
HttpResponse httpResponse = HttpContext.Current.Response; httpResponse.Clear(); httpResponse.ClearContent(); httpResponse.ClearHeaders(); httpResponse.AddHeader("content-disposition", "attachment;filename=" + txt1.Text + ".xls"); string strpath = ConfigurationManager.AppSettings["Downloads"].ToString() + txt1.Text; httpResponse.ContentType = "application/vnd.ms-excel;"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); string style = @"<style> .textmode { mso-number-format:\@; } </style>"; httpResponse.Write(style); httpResponse.Output.Write(sw.ToString()); httpResponse.Flush(); httpResponse.Close(); httpResponse.End();
我在Web.Config中的AddKey是
<add key="Downloads" value="C:\Users\MyName\Desktop\Downloads"/>
在这里,我怎么能给这个添加键值
也许这可以帮助你WebClient.DownloadFile
using (var client = new WebClient()) { client.DownloadFile(theUrl, Path.Combine(ConfigurationManager.AppSettings["Downloads"].ToString(), "myXls.xls")); }