Click here to Skip to main content
13,052,163 members (38,720 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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));
for (int i = 0; i < finfo.Length; i++)
  list.Value = finfo[i].ToString();

protected void lstpdfs_SelectedIndexChanged(object sender, EventArgs e)
string filePath = @"C:\folder\PDFs\"+ lstpdfs.SelectedValue;
Session["pdfFileName"] = filePath ;
Response.Write("<script type='text/javascript'>'../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.AddHeader("content-length", buffer.Length.ToString());

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 20:28pm
Updated 27-Jun-12 20:31pm
digimanus 28-Jun-12 3:06am
set the content-disposition header too

1 solution

Rate this: bad
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?
Member 8683058 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 Jun 2012
Copyright © CodeProject, 1999-2017
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