Create links to pdf fileshttp://forums.asp.net/t/1806851.aspx/1?Create+links+to+pdf+filesFri, 01 Jun 2012 15:54:59 -040018068514994533http://forums.asp.net/p/1806851/4994533.aspx/1?Create+links+to+pdf+filesCreate links to pdf files <p>I hope this post is in the correct forum. We have a folder on the server that has pdf files. The file names are in the format of 'report_name_propname_04_21_12.pdf'. The report_name is different as is the prop_name and 04 is the month, 21 is the day of month, and the 12 is the year. The goal is to have links on the web&nbsp;page that has the prop_name(s). When clicked it would display a list of months as links. ie 01,02,03,...11,12 under the propname link. When these month&nbsp;links are clicked the web&nbsp;page would display a list of links of the pdf files. The part of displaying the pdf link I have. The question I have is how can this be achived in code? Is there a control for this functionality? I think it is&nbsp;like an Excel pivot table.</p> <p>Does anyone have a suggestion?</p> <p>Thank you in advance,</p> <p>Jim</p> 2012-05-23T21:07:52-04:004994671http://forums.asp.net/p/1806851/4994671.aspx/1?Re+Create+links+to+pdf+filesRe: Create links to pdf files <p>iterate in the directory finding files</p> <p>put into a LIst&lt;&gt;</p> <p>bind to a grid.</p> <p></p> 2012-05-24T02:13:06-04:004997134http://forums.asp.net/p/1806851/4997134.aspx/1?Re+Create+links+to+pdf+filesRe: Create links to pdf files <p align="left">Hi, you can create a DataTable with four columns (Year, Month, Day, FilePath) to store the file information. With the methods in DirectoryInfo, FileInfo, you can get the Year, Month, Day, FilePath information from the files. Then, store the information into DataTable, bind Year column to a DropDownList, bind Month column to another DropDownList. I made an example and tested on my computer, you can refer to it:</p> <p align="left">Default.aspx:</p> <pre class="prettyprint">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:DropDownList ID=&quot;DropDownList1&quot; runat=&quot;server&quot; AutoPostBack=&quot;true&quot; AppendDataBoundItems=&quot;true&quot; onselectedindexchanged=&quot;DropDownList1_SelectedIndexChanged&quot;&gt; &lt;asp:ListItem&gt;Please select Year...&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;asp:DropDownList ID=&quot;DropDownList2&quot; runat=&quot;server&quot; AutoPostBack=&quot;true&quot; onselectedindexchanged=&quot;DropDownList2_SelectedIndexChanged&quot;&gt; &lt;/asp:DropDownList&gt; &lt;asp:DropDownList ID=&quot;DropDownList3&quot; runat=&quot;server&quot;&gt; &lt;/asp:DropDownList&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p align="left">Default.aspx.cs:</p> <pre class="prettyprint">public DataTable table = new DataTable(); protected void Page_Load(object sender, EventArgs e) { table = GetFiles(); if (!this.IsPostBack) { List&lt;string&gt; Year = GetYears(); this.DropDownList1.DataSource = Year; this.DropDownList1.DataBind(); } } protected DataTable GetFiles() { DataTable table = new DataTable(); DataColumn column = new DataColumn("Year", System.Type.GetType("System.String")); table.Columns.Add(column); column = new DataColumn("Month", System.Type.GetType("System.String")); table.Columns.Add(column); column = new DataColumn("Day", System.Type.GetType("System.String")); table.Columns.Add(column); column = new DataColumn("FilePath", System.Type.GetType("System.String")); table.Columns.Add(column); string Year = ""; string Month = ""; string Day = ""; string FilePath = ""; DirectoryInfo direc = new DirectoryInfo("File Directory"); FileInfo[] FileNames = direc.GetFiles(); foreach (FileInfo file in FileNames) { string FileName = file.FullName; string FileEx = FileName.Substring(FileName.LastIndexOf(".")); if (FileEx == ".pdf") { Year = FileName.Substring(FileName.LastIndexOf(".") - 2, 2); Day = FileName.Substring(FileName.LastIndexOf(".") - 5, 2); Month = FileName.Substring(FileName.LastIndexOf(".") - 8, 2); FilePath = file.FullName; DataRow row = table.NewRow(); row["Year"] = Year; row["Day"] = Day; row["Month"] = Month; row["FilePath"] = FilePath; table.Rows.Add(row); } } return table; } protected List&lt;string&gt; GetYears() { List&lt;string&gt; list = new List&lt;string&gt;(); list = (from myRow in table.AsEnumerable() select myRow.Field&lt;string&gt;("Year")).Distinct&lt;string&gt;().ToList&lt;string&gt;(); return list; } protected List&lt;string&gt; GetMonths(string year) { List&lt;string&gt; list = new List&lt;string&gt;(); if (year != null) { list = (from myRow in table.AsEnumerable() where myRow.Field&lt;string&gt;("Year") == year select myRow.Field&lt;string&gt;("Month")).Distinct&lt;string&gt;().ToList&lt;string&gt;(); } return list; } protected List&lt;string&gt; GetFilePathes(string year,string month) { List&lt;string&gt; list = new List&lt;string&gt;(); if (year != null &amp;&amp; month != null) { list = (from myRow in table.AsEnumerable() where myRow.Field&lt;string&gt;("Year") == year &amp;&amp; myRow.Field&lt;string&gt;("Month") == month select myRow.Field&lt;string&gt;("FilePath")).Distinct&lt;string&gt;().ToList&lt;string&gt;(); } return list; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string Year = this.DropDownList1.SelectedValue; List&lt;string&gt; Month = GetMonths(Year); this.DropDownList2.Items.Clear(); this.DropDownList2.DataSource = Month; this.DropDownList2.DataBind(); ListItem item = new ListItem(); item.Value = null; item.Text = "Please select a month..."; DropDownList2.Items.Add(item); item.Selected = true; } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { string Year = this.DropDownList1.SelectedValue; string Month = this.DropDownList2.SelectedValue; List&lt;string&gt; FilePathes = GetFilePathes(Year, Month); this.DropDownList3.DataSource = FilePathes; this.DropDownList3.DataBind(); } </pre> <p align="left"></p> 2012-05-25T09:42:23-04:005006704http://forums.asp.net/p/1806851/5006704.aspx/1?Re+Create+links+to+pdf+filesRe: Create links to pdf files <p>Hi Allen,</p> <p>Thank you for your response. Now that I have a datatable, how can I loop thru it and select filepath where year, month and day are a certain value?</p> <p>Thanks in advance,</p> <p>Jim</p> 2012-05-31T21:14:44-04:005008049http://forums.asp.net/p/1806851/5008049.aspx/1?Re+Create+links+to+pdf+filesRe: Create links to pdf files <p>Hi Allen,</p> <p>how do I mark your reply as the answer?</p> <p>Thanks,</p> <p>Jim</p> 2012-06-01T15:54:59-04:00