单击列表框中的不同pdf链接时无法打开不同的pdf [英] Not able to open different pdf on clicking different pdf links in list box

查看:89
本文介绍了单击列表框中的不同pdf链接时无法打开不同的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在列表框中显示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>"); }



在PDFDISPLAY.ASPX上,我已编码为



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

推荐答案

可能是缓存问题.您可以尝试设置响应内容过期或缓存设置,也可以尝试在查询字符串后附加一个随机数或Guid,例如?c = {Guid.NewGuid()},以便浏览器将不得不请求新内容(我的javascript中的PdfDisplay.aspx可能需要,因为该URL不会改变).不知道那是什么还是不确定包含错误值的列表.我想这虽然是浏览器缓存.

另外,查看您的selectedIndex发生了变化,我想您可能希望使用一个占位符来代替Java语言,而不是仅仅发送回响应流,而是将占位符更新到该占位符中.经过几次回发后,您是否查看了html源代码并确保它不只是一次又一次地添加javascript?
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?


这篇关于单击列表框中的不同pdf链接时无法打开不同的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆