我用ASP。NET做的文件上传的程序,代码如下:
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile=new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename="+
HttpUtility.UrlEncode(DownloadFile.FullName,
System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
} private void Button1_Click(object sender, System.EventArgs e)
{
FileDownload(@"D:\file\1.EXCEL");
}
为什么别人在打开的时候EXCEL会弹出个对话框找不到'C:\Documents and Settings\Guest\Local Settings\Temporary Internet Files\Content.IE5\D%3a%5c\file\%5c%2d\1.EXCEL'.请检查档名是否有拼错或文件是否存在!
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile=new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename="+
HttpUtility.UrlEncode(DownloadFile.FullName,
System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
} private void Button1_Click(object sender, System.EventArgs e)
{
FileDownload(@"D:\file\1.EXCEL");
}
为什么别人在打开的时候EXCEL会弹出个对话框找不到'C:\Documents and Settings\Guest\Local Settings\Temporary Internet Files\Content.IE5\D%3a%5c\file\%5c%2d\1.EXCEL'.请检查档名是否有拼错或文件是否存在!
System.IO.StringWriter sw = new System.IO.StringWriter();
sw.WriteLine(s);
Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmdd") + ".xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();