我如何...解决pdf下载代码问题。 [英] How do I... Resolve pdf downloading code issue.
问题描述
以下是我的问题情节。
我开发了一个网络sie使用ASP.net。
我在本网站使用母版页,在该母版页上我有菜单控件,退出按钮。
我有一个网页有pdf下载功能。
以下是我的pdf下载代码。
DirectoryInfo myDir = new DirectoryInfo(C:\\Bills+ billmonth);
FileInfo [] files = myDir.GetFiles(PDFName +* .pdf);
byte [] bytes = null;
string path = files [0] .FullName;
bytes = System.IO.File.ReadAllBytes(path);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType =application\\pdf;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader(Content-disposition,attachment; filename =+ files [0] .Name);
Response.BinaryWrite(bytes);
Response.End();
以上代码在浏览器中工作正常。
但我的问题从这里开始,当我的pdf下载完成并且我尝试从我的网站注销然后注销功能无效。要从网站注销我需要每次刷新页面。
请帮帮我
谢谢,
申请
受保护 < span class =code-keyword> void lnkfilepath_Click( object sender,EventArgs e) // ur link button
{
string filename = lnkfilepath.Text;
string Filpath = Server.MapPath( 〜/ Attachments / + filename);
DownLoad(Filpath);
}
public void DownLoad( string FName)
{
string path = FName;
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader( Content-Disposition, attachment; filename = + file.Name);
Response.AddHeader( Content-Length,file.Length.ToString()) ;
Response.ContentType = application / octet-stream; // 下载所有类型的文件..
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write( 此文件不存在。);
}
}
你好shashikant86,你可以'了解代码发生了什么,
只需将下面的代码放入下载代码后自动刷新页面
Respons.Redirect( yourpage.aspx)
Hi,
Below is my problem scenario.
I have developed one web sie using ASP.net.
I am using Master page in this website and on that master page i have menu contorls, Log out button placed.
I have one web page which is having pdf downloading functionality.
Below is my pdf downloading code.
DirectoryInfo myDir = new DirectoryInfo("C:\\Bills" + billmonth); FileInfo[] files = myDir.GetFiles(PDFName + "*.pdf"); byte[] bytes = null; string path = files[0].FullName; bytes = System.IO.File.ReadAllBytes(path); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = "application\\pdf"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AddHeader("Content-disposition", "attachment; filename=" + files[0].Name); Response.BinaryWrite(bytes); Response.End();
Above code is working fine in browser.
But my problem starts here ,when my pdf download compltets and i try to log out from my web site then log out functionality not working. To logout from web site i need to refresh page every time.
Please help me
Thanks,
application
protected void lnkfilepath_Click(object sender, EventArgs e) // ur link button { string filename = lnkfilepath.Text; string Filpath = Server.MapPath("~/Attachments/" + filename); DownLoad(Filpath); } public void DownLoad(string FName) { string path = FName; System.IO.FileInfo file = new System.IO.FileInfo(path); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; // download all types of files.. Response.WriteFile(file.FullName); Response.End(); } else { Response.Write("This file does not exist."); } }
Can u use this above code..its support all types of file downloading
Reference Click Here
Hi shashikant86 , you can't understand what happening the code ,
just put the below code in after download code it refresh the page automatically
Respons.Redirect("yourpage.aspx")
这篇关于我如何...解决pdf下载代码问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!