C# 如何下载提交/创建的pdf文件?

C# 如何下载提交/创建的pdf文件?,c#,asp.net,C#,Asp.net,我想替换>>>>Response.WriteFile(文件路径) 尝试此标题application/octet-stream而不是application/pdf,您还需要附加标题 Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); Response.TransmitFile(Server.

我想替换>>>>Response.WriteFile(文件路径) 尝试此标题
application/octet-stream
而不是
application/pdf

,您还需要附加标题

Response.ContentType = "Application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); 
Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); 
Response.Flush() 
Response.End();

这里应该做的是另一个例子,我有另一个问题请。我将把哪个目录放到这个响应中;在我的示例中,我假设您的文件位于应用程序根目录中的文件文件夹中,它的名称YourFileName.pdf~表示根目录,因此如果您的pdf位于根目录中,您只需说“~/YourFileName.pdf”,依此类推
Response.ContentType = "Application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); 
Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); 
Response.Flush() 
Response.End();
FileInfo fi = new FileInfo(@Request.PhysicalApplicationPath + File_Name);//
long sz = fi.Length;
Response.ClearContent();
Response.ContentType = MimeType(Path.GetExtension(File_Name));
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(File_Name)));
Response.AddHeader("Content-Length", sz.ToString("F0"));
Response.TransmitFile(File_Name);
Response.End();