Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 02, 2010 03:17 PM by nagappmking
Jan 20, 2010 12:41 PM|LINK
You will need to iterate through the folder that contains your PDFs to display each one. Here's a sample that adds them to a ListBox and when you select a PDF it gets displayed.
<asp:Label ID="Label1" runat="server" Text="PDF Files" />
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
private string path = @"c:\PDF_Files\";
protected void Page_Load(object sender, EventArgs e)
DirectoryInfo di = new DirectoryInfo(path);
FileInfo fi = di.GetFiles();
foreach (FileInfo file in fi)
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
WebClient client = new WebClient();
Byte buffer = client.DownloadData(path + ListBox1.SelectedValue);
Response.ContentType = "application/pdf";
Jan 21, 2010 03:52 AM|LINK
Thanks so much friend!
your codes really helped me, but not for my current prblm, i used it in a different application.
the PDFs working for my web page which has a GridView in it. what i did is:
I stored all the PDF files in a hard drive and then took a copy and paste it the "C:\Documents and Settings\mhelaman\My Documents\Visual Studio 2008\Projects\MoIFacSurvey"
which is the folder which contains all the pages of my project.
problem was, if i stroed the PDFs in my Solution Explorer, then the website was getting loaded, now when i put them there in the Visual Studio 2008 folder, Will it again make my website loaded, or it is fine???
Thats my question, hope you can answer...
Jan 21, 2010 12:54 PM|LINK
I'm not sure I completely follow you, but no matter where you store them, they will not impact your website. They will only get loaded when you select them from within your GridView, which in turn will reference the folder location you have them stored
in. If you are asking whether they will be loaded into memory when you start your website up, the answer is no. Does that answer your question?
Jan 24, 2010 05:14 AM|LINK
that was what i was aksing. but good that the answer is NO.
Thanks for you support.
Dear, I got another problem.
I got a TreeView in my web page, and beside i've put a GridView, the TreeView contains Countries and Provinces (ChildNode), what i want is that by clicking any provinces (ChildNode) of the tree View, I want the GridView to show the selected Node's Details.
I mean, there should be a GridView by default, containing one of the TreeView Node's data, and then by clicking on any of the other nodes, the GridView should change the data accordingly,
Is it something like i should define SQL query for each Node? if yes, shall i write the codes under "TreeView1.SelectedNodeChanged" ? if I try this, then i am not able to define a particular node.
Mar 10, 2010 07:19 PM|LINK
Thank you, Thank U THANK U !!!
This worked perfectly. But now how do I force the user to close the PDF before going back to do something else in the webpage?
I am getting greedy now.
BTW, I am using VB.NET not C#
May 07, 2010 07:52 AM|LINK
The problem scenerio is that i have some doc files residing at "F:\\test\\*".
I want to list out and open doc files from my asp.net application on hyperlink click, language is C#.
I went through your pdf example but it results into error
An invalid character was found in text content. Line 1, Position 1
mail me at email@example.com
May 07, 2010 08:35 AM|LINK
This article should get you started:
Although it is in VB, you should be able to convert easy enough
Jun 21, 2010 08:01 PM|LINK
I'm using this snippet this way. I'm using a FileUpload control to upload files to a dir and show the uploaded files in ListBox user can double click the file name in the Listbox and open the file he uploaded & When he tries to upload a new file the code
in the Page_Load executed and the Selection in Listbox is still there Itried ClearSelection() , SelectionIndex = -1. But the item is still selected. so it won't allow me to upload a new file in there. Please tell me if I'm missing anything here. Thanks
01.if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "click")
03. int idx = LstBxUploadedFiles.SelectedIndex;
04. ListItem item = LstBxUploadedFiles.SelectedItem;
06. DirectoryInfo di = new DirectoryInfo(ConfigurationManager.AppSettings["DocumentsLocation"] + "\\" + (string)Session["CreatedFolderName"]);
07. FileInfo files = di.GetFiles();
08. foreach (FileInfo fi in files)
10. if (fi.Name == item.Text)
13. Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
14. Response.AddHeader("Content-Length", fi.Length.ToString());
15. string CId = Request["__EVENTTARGET"];
26. LstBxUploadedFiles.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(LstBxUploadedFiles, "click"));
Aug 07, 2010 01:04 PM|LINK
Note: If you installed pdf plugin to your browser, it will automatically displayed.
The above code will display save dialog to save pdf even if you have a browser with pdf plugin installed. So that the user can download directly instead of displaying it in browser and then saving..
Best of luck
Sep 02, 2010 03:17 PM|LINK
You can use HTML tag called <iframe> and src attribute as, pdf path this will display the pdf automatically, there are some attributes with URL called toolbar=no&menu=no etc. These will hide the pdf toolbar and menu options. If you want to show pdf for terms
and conditions kind, then this will be very useful.