Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void ShowDocument(string fileName, byte[] fileContent)
    {
        //Split the string by character . to get file extension type
        string[] stringParts = fileName.Split(new char[] { '.' });
        string strType = stringParts[1];
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
        //Set the content type as file extension type
        Response.ContentType = strType;
        //Write the file content
        this.Response.BinaryWrite(fileContent);
        this.Response.End()    

now how to target this file to new window of browser
Posted

Hi,

C#
Response.Write("<script>");
Response.Write("window.open('[Your PDF path]', '[Tab Name]');");
Response.Write("</script>");
 
Share this answer
 
Comments
Nilesh Patil C 28-Dec-12 2:45am    
how can i get path of pdf .while i am fetching it from database
Suvabrata Roy 28-Dec-12 2:47am    
Save the stream in a folder then get the path of that file, it will save you overhead if you once save the file, then you can serve it to multiple clients without reading that each time from DB. IF YOUR PDF CONTENT IS NOT GOING TO CHANGE ON RUN TIME
C#
// Try this, it is working perfect in my project...

Response.Flush();
Response.Clear();

Response.AppendHeader("content-disposition", "inline;filename=yourpdfname.pdf");
Response.ContentType = "application/pdf";

Response.BinaryWrite(fileContent);
Response.Flush();
 
Share this answer
 
Is Google [^]really broken at your end today? This has been discussed/done so many times before.
 
Share this answer
 
Hi, firts of all lets do some improvements.
What could be if a file name contains more than 1 dot ?)
I think it would be an exceptional state!
SO,strType can be resolved with help of Path class from System.IO namespace:
C#
string strType=Path.GetExtension(filename);


As concerns you concrete problem , please look at this MSDN
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900