尝试使用Response.AddHeader()下载文件时如何添加路径

时间:2019-03-21 06:25:38

标签: .net

我不知道如何添加在Web.Config文件中添加的“键值”。

此代码未下载任何文件:

WebConfig代码:

if (!string.IsNullOrEmpty(FileName))
            {
                var contentList = db.DataFile.Where(q => q.ID == id && q.FileName.Equals(FileName)).OrderBy(q => q.QID).Select(q => q.TextValue).ToList();

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < contentList.Count; i++)
                {
                    sb.AppendFormat("{0}", contentList[i]);

                }
                var byteArray = Encoding.Project.GetBytes(sb.ToString());
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + FileName + "\"");
                Response.ContentType = "application/octet-stream";
                Response.BinaryWrite(byteArray);               
                Response.End();
            }

1 个答案:

答案 0 :(得分:0)

要从web.config获取关键值,可以使用以下代码:

string value = System.Configuration.ConfigurationManager.AppSettings[“AutocoolPath”];