Click here to Skip to main content
11,478,896 members (57,976 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# PDF
I m trying to display the pdf files in list box and on clicking on the file (on selected index changed) i want to open that particular file.
But i m nt able to do so as i m getting the single file(Clicked first) on click of any link.
 
string var = txtpan.Text;
ListItem list = new ListItem();
DirectoryInfo dinfo = new DirectoryInfo(@"C:\vrishali\PDFs\");
/* get files from the directory as a files collection */
FileInfo[] finfo = dinfo.GetFiles(string.Format("{0}*.pdf",var));
lstpdfs.Items.Clear();
//files=Directory.GetFiles(@"C:\folder\PDFs\",string.Format("{0}*.pdf",var));
for (int i = 0; i < finfo.Length; i++)
{            
  list.Value = finfo[i].ToString();
  lstpdfs.Items.Add(list.Value);
}
protected void lstpdfs_SelectedIndexChanged(object sender, EventArgs e)
{
string filePath = @"C:\folder\PDFs\"+ lstpdfs.SelectedValue;
Session["pdfFileName"] = filePath ;
Response.Write("<script type='text/javascript'>detailedresults=window.open('../PdfDisplay.aspx');</script>"); }

ON PDFDISPLAY.ASPX I have coded as
string path = Session["pdfFileName"].ToString();
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
Response.ClearContent();
Response.Flush();
Response.Close();
}
This is my code. I am not able to clear the response stream as i am getting first clicked file on click of any other link.
please help
Posted 27-Jun-12 21:28pm
Edited 27-Jun-12 21:31pm
JF201553.7K
v2
Comments
digimanus at 28-Jun-12 3:06am
   
set the content-disposition header too

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Might be a caching issue. You could try setting the response content expires or caching settings or you can try and append a random number or Guid to the querystring e.g. ?c={Guid.NewGuid()} so that the browser will have to request for new content (might be needed for the PdfDisplay.aspx in your javascript since that url doesn't change I imagine). Not sure if that is what it is or if you have an issue with the list containing the wrong values. I imagine it is the browser caching though.

Also, looking at your selectedindex changed, I would imagine instead of response.write you might want a placeholder that you can update that javascript into instead of just sending back to the response stream. Have you looked at your html source after a few postbacks and make sure it isn't just adding the javascript again and again?
  Permalink  
Comments
Member 8683058 at 10-Jul-12 4:25am
   
Thanks Trak4Net769 for ur soln. it helped

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 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 28 Jun 2012
Copyright © CodeProject, 1999-2015
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