HttpContext.Current.Response.WriteFile 不支持路径格式
HttpContext.Current.Response.WriteFile path's format is not supported
异常在ASP.NET"The given file format is not supported",在
HttpContext.Current.Response.WriteFile
, 下面是我的代码
string DocumentPath = "D:/Live//web/";
Path.Combine(DocumentPath, FileName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + FileName);
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.WriteFile(DocumentPath);
HttpContext.Current.Response.End();
response.Write(DocumentPath);
我认为您还必须插入文件名。
试试这个-
HttpContext.Current.Response.WriteFile(DocumentPath+ FileName);
更新
试试这行代码
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="test.xls");
而不是这个-
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + FileName);
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
更新 2
简短的回答是,出于安全原因,您不能将文件保存在客户端的计算机上。
所以你能做的只有这一行
Response.AddHeader("Content-Disposition", "attachment;filename="+fileName);
没有 DocumentPath
.
最后更新
//write file to the server
string lines = "First line.\r\nSecond line.\r\nThird line.";
System.IO.StreamWriter file = new System.IO.StreamWriter("test.txt");
file.WriteLine(lines);
file.Close();
//read the file from server
string david = File.ReadAllText("test.txt");
异常在ASP.NET"The given file format is not supported",在
HttpContext.Current.Response.WriteFile
, 下面是我的代码
string DocumentPath = "D:/Live//web/";
Path.Combine(DocumentPath, FileName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + FileName);
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.WriteFile(DocumentPath);
HttpContext.Current.Response.End();
response.Write(DocumentPath);
我认为您还必须插入文件名。
试试这个-
HttpContext.Current.Response.WriteFile(DocumentPath+ FileName);
更新
试试这行代码
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="test.xls");
而不是这个-
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + FileName);
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
更新 2
简短的回答是,出于安全原因,您不能将文件保存在客户端的计算机上。 所以你能做的只有这一行
Response.AddHeader("Content-Disposition", "attachment;filename="+fileName);
没有 DocumentPath
.
最后更新
//write file to the server
string lines = "First line.\r\nSecond line.\r\nThird line.";
System.IO.StreamWriter file = new System.IO.StreamWriter("test.txt");
file.WriteLine(lines);
file.Close();
//read the file from server
string david = File.ReadAllText("test.txt");