Open pdf in browser with different names

My program generates PDF in Browser (open the PDF in the browser). But when I want save the file in computer, the default name of PDF is always the same (the name of my class). I want to pass the name for different pdf's... This is my code:

protected void displayPDF(string filePath, string filename)
{
    Response.Clear();
    Response.ContentType = "Application/PDF";
    //what i do with filename?
    Response.WriteFile(filePath);
    Response.Flush();
    Response.End();
}

I tried this:

Response.AddHeader("Content-Disposition", "attachment; filename=myfile.pdf");

But this way, pdf doesn't open in browser, pass like an attachment.

Can you help me? Thanks.


Try HttpResponse.TransmitFile(path) eg. http://bojanskr.blogspot.ca/2012/03/providing-file-for-download-trough-save.html?m=1

链接地址: http://www.djcxy.com/p/46826.html

上一篇: Chrome无法识别附件文件名

下一篇: 在不同名称的浏览器中打开pdf