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\");
FileInfo[] finfo = dinfo.GetFiles(string.Format("{0}*.pdf",var));
lstpdfs.Items.Clear();
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