我正在尝试生成并下载PDF文件。它一直说文件类型错误或文件被损坏。ASP.Net C#生成并下载PDF文件
这里是我的代码的帮助
protected void downloadFile(int index)
{
string strContent = "<html> <body> <div> <b> Tjeu! </b> </div> <div> <INPUT TYPE=CHECKBOX NAME=\"maillist\" disabled=\"disabled\">Yes! Put me on the list! </div> </body> </html>";
string attach = "attachment; filename=wordtest.pdf";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
HttpContext.Current.Response.AddHeader("content-disposition", attach);
HttpContext.Current.Response.Write(strContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
THX)
当你用记事本打开现有的PDF文件(比如)你不会看到HTML。将HTML文件重命名为.PDF不会使其成为PDF。 – spender 2011-04-25 13:35:19