Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 27-Dec-12 20:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Response.Write("<script>");
Response.Write("window.open('[Your PDF path]', '[Tab Name]');");
Response.Write("</script>");
  Permalink  
Comments
Nilesh Patil C at 28-Dec-12 2:45am
   
how can i get path of pdf .while i am fetching it from database
Suvabrata Roy at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

 
// 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();
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Is Google [^]really broken at your end today? This has been discussed/done so many times before.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:
string strType=Path.GetExtension(filename);
 
As concerns you concrete problem , please look at this MSDN
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 432
1 OriginalGriff 250
2 CPallini 240
3 Abdul Samad KP 145
4 George Jonsson 119
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100