Purpose of Code:
I am attempting to create a page that opens up a virtual directory folder on my server(IIS).The folder will be based on a dropdown selection. For example, Blue will onmpen the Blue Folder and Red will open the Red Folder. Once the folder contents is listed
on my page then the user can click on the link and open the file.
Error Recieving:
I havethe ability to list the folder contents but when I click on the link it does not go to the correct link location.
Here is my Code. I have omittedthe Dropdown portion of the code.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string DataDirectory = "/storemailboxes/s012/r001/PackList/";
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(DataDirectory));
articleList.DataSource = dirInfo.GetFiles("*.html");
articleList.DataBind();
}
}
Dim DataDirectory As String = "/storemailboxes/s012/r001/PackList/"
Dim dirInfo As DirectoryInfo = New DirectoryInfo(Server.MapPath(DataDirectory))
For Each f As FileInfo In dirInfo.GetFiles()
'Create a dynamic linkbutton, hyperlink, imagebutton, etc.
Dim newFileLink As LinkButton = New LinkButton
'set properties and stuff
newFileLink.Text = f.Name
filesPlaceHolder.Controls.Add(newFileLink)
Next
You don't really need a data templating object to bind the source.
Just do this within a sub procedure and create some dynamic control for each file and add them to a container of some sort (placeholder, label, panel, etc.)
<asp:placeholder id ="filesPlaceHolder" runat="server">
<!-- Dynamic control will be populated here... -->
</asp:placeholder>
Check out my website: http://www.TheTradeBox.com
Love collecting video games, movies and board games!
Enjoying my '11 WRX, so sexy...
@Mastan That worked thanks. THe next Issue I am having is thow to make that link dymanic based on the drop down.
For Example my dropdown is "ddlStoreNumber", if this store selected is 009 it would then update the DataNavigateUrlFormatString attribute to "storemailboxes/s009/r001/PackList/{0}"
duanegowe
Member
57 Points
118 Posts
Directory Listing Of Folder and Opening item
Jul 20, 2012 10:44 PM|LINK
Hey Guru's
I'm stuck in my coding.
Purpose of Code:
I am attempting to create a page that opens up a virtual directory folder on my server(IIS).The folder will be based on a dropdown selection. For example, Blue will onmpen the Blue Folder and Red will open the Red Folder. Once the folder contents is listed on my page then the user can click on the link and open the file.
Error Recieving:
I havethe ability to list the folder contents but when I click on the link it does not go to the correct link location.
Here is my Code. I have omittedthe Dropdown portion of the code.
C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataGrid runat="server" id="articleList" Font-Name="Verdana" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True"> <Columns> <asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name" /> <asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" /> <asp:BoundColumn DataField="Length" HeaderText="File Size" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,### bytes}" /> </Columns> </asp:DataGrid> </div> </form> </body> </html>CS:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string DataDirectory = "/storemailboxes/s012/r001/PackList/"; DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(DataDirectory)); articleList.DataSource = dirInfo.GetFiles("*.html"); articleList.DataBind(); } }Thanks
mebinici
Participant
815 Points
256 Posts
Re: Directory Listing Of Folder and Opening item
Jul 20, 2012 11:22 PM|LINK
Dim DataDirectory As String = "/storemailboxes/s012/r001/PackList/" Dim dirInfo As DirectoryInfo = New DirectoryInfo(Server.MapPath(DataDirectory)) For Each f As FileInfo In dirInfo.GetFiles() 'Create a dynamic linkbutton, hyperlink, imagebutton, etc. Dim newFileLink As LinkButton = New LinkButton 'set properties and stuff newFileLink.Text = f.Name filesPlaceHolder.Controls.Add(newFileLink) NextYou don't really need a data templating object to bind the source.
Just do this within a sub procedure and create some dynamic control for each file and add them to a container of some sort (placeholder, label, panel, etc.)
Love collecting video games, movies and board games!
Enjoying my '11 WRX, so sexy...
Mastan Oli
Contributor
5088 Points
998 Posts
Re: Directory Listing Of Folder and Opening item
Jul 20, 2012 11:23 PM|LINK
Add DataNavigateUrlFormatString="storemailboxes/s012/r001/PackList/{0}" attribute in th hyperlink, like
<asp:DataGrid runat="server" ID="articleList" Font-Name="Verdana" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True"> <Columns> <asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name" DataNavigateUrlFormatString="storemailboxes/s012/r001/PackList/{0}" /> <asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" /> <asp:BoundColumn DataField="Length" HeaderText="File Size" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,### bytes}" /> </Columns> </asp:DataGrid>playingOOPS | மெய்ப்பொருள் காண்பதறிவு
Mark as Answer If you find helpful
duanegowe
Member
57 Points
118 Posts
Re: Directory Listing Of Folder and Opening item
Jul 23, 2012 04:56 PM|LINK
@Mastan That worked thanks. THe next Issue I am having is thow to make that link dymanic based on the drop down.
For Example my dropdown is "ddlStoreNumber", if this store selected is 009 it would then update the DataNavigateUrlFormatString attribute to "storemailboxes/s009/r001/PackList/{0}"