I want to create a web page for me to access documents that I use for songs (song sheets). Aside from creating a page that I update with the link to each document as I add them, is there a way to show the directory folder they are contained in so that it
is dynamic and I don't have to update the page each time I add a file to it? I tried creating an FTP site but had issues with ports ect so I went the way of a web site which works but has that added issue of having to update my page for each file added....
Your scenario will work fine in local machine not in the Network! I mean you web application is deployed in your local machine, where you can hardcode the drive or folder information!
You can take advantage of System.IO namespace which contains Directory and File class to retrieve the files and display it dynamically!
You can also consider using Silverlight app for this!
NOTE: File Upload Doesn't work in Update Panel as it needs a full postback thats why it has to be outside the Update Panel or Use <AsyncUpload> You can find this in the AJAX ControlToolKit
Please remember to click “Mark as Answer” on the post that helps you.
Thanks everyone for the help. I will try to use this guidance to acheive what I need. I will hopefully be able to get this working. I have limited programming skills especially in C#, I am more inclined to VBA and a little vb.net and HTML but i'll give it
a shot :)
you provided and was able to get the first three demos to work however the 4th one produced an error at the following line (i think) (strCurrentScript = arrURL[arrURL.Length-1];)... any ideas what could be causing that?
robbyaube
Member
31 Points
39 Posts
Web page to show file directory
Apr 24, 2012 01:31 PM|LINK
Hi,
I want to create a web page for me to access documents that I use for songs (song sheets). Aside from creating a page that I update with the link to each document as I add them, is there a way to show the directory folder they are contained in so that it is dynamic and I don't have to update the page each time I add a file to it? I tried creating an FTP site but had issues with ports ect so I went the way of a web site which works but has that added issue of having to update my page for each file added....
Thanks for any help with this.
robby
Sparkers
Contributor
2086 Points
470 Posts
Re: Web page to show file directory
Apr 24, 2012 01:38 PM|LINK
Make use of AJAX or JQuery to handle this.. You can write to code to fetch if there are any new files and to display it.
Example, in AJAX you can use UpdatePanels to get this issue resolved.
robbyaube
Member
31 Points
39 Posts
Re: Web page to show file directory
Apr 24, 2012 01:45 PM|LINK
Thanks for the answer, would you have any tutorials available somewhere on how to use the above solution?
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: Web page to show file directory
Apr 24, 2012 02:00 PM|LINK
Hi,
Your scenario will work fine in local machine not in the Network! I mean you web application is deployed in your local machine, where you can hardcode the drive or folder information!
You can take advantage of System.IO namespace which contains Directory and File class to retrieve the files and display it dynamically!
You can also consider using Silverlight app for this!
http://www.codeproject.com/Articles/208173/Silverlight-5-Features-Local-File-System-Access-wi
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
Sparkers
Contributor
2086 Points
470 Posts
Re: Web page to show file directory
Apr 24, 2012 02:03 PM|LINK
Okay now..
I do not have the complete example but this is waht you can achieve..
read the following article..
http://www.techrepublic.com/article/obtaining-file-and-directory-information-in-aspnet/5285107
Whatever code you develop fo fetch the directory listing just put that code in
<asp:UpdatePanel Id="upImage" UpdateMode="Always">
<---Code for Directory--->
</asp:UpdatePanel>
<asp:FileUpload Id="fuImage">
</asp:FileUpload>
NOTE: File Upload Doesn't work in Update Panel as it needs a full postback thats why it has to be outside the Update Panel or Use <AsyncUpload> You can find this in the AJAX ControlToolKit
robbyaube
Member
31 Points
39 Posts
Re: Web page to show file directory
Apr 24, 2012 02:54 PM|LINK
Thanks everyone for the help. I will try to use this guidance to acheive what I need. I will hopefully be able to get this working. I have limited programming skills especially in C#, I am more inclined to VBA and a little vb.net and HTML but i'll give it a shot :)
Robby
Motley
Star
13789 Points
2449 Posts
MVP
Re: Web page to show file directory
Apr 24, 2012 05:56 PM|LINK
Use a method in the System.IO namespace to get a list of files, then bind that collection to a repeater control that contains hyperlinks.
Html:
<asp:Repeater ID="rptFileList" runat="server"> <ItemTemplate> <a href="Download.aspx?filename=<%# System.Net.WebUtility.HtmlEncode(Eval("filename").ToString()) %>"><%# System.Net.WebUtility.HtmlEncode(Eval("filename").ToString()) %></a> </ItemTemplate> </asp:Repeater>Codebehind:
protected void Page_Load(object sender, EventArgs e) { var result=System.IO.Directory.GetFiles(Server.MapPath(".")).AsEnumerable().Select(r => new { filename=System.IO.Path.GetFileName(r) }); rptFileList.DataSource=result; rptFileList.DataBind(); }Should probablty URL encode the part in the hyperlink href as well, but I was lazy.
robbyaube
Member
31 Points
39 Posts
Re: Web page to show file directory
Apr 25, 2012 12:36 PM|LINK
Hi, I checked out the link:
(http://www.techrepublic.com/article/obtaining-file-and-directory-information-in-aspnet/5285107)
you provided and was able to get the first three demos to work however the 4th one produced an error at the following line (i think) (strCurrentScript = arrURL[arrURL.Length-1];)... any ideas what could be causing that?
Sparkers
Contributor
2086 Points
470 Posts
Re: Web page to show file directory
Apr 25, 2012 02:30 PM|LINK
What is the error?
Debug it to get the error and the line..
robbyaube
Member
31 Points
39 Posts
Re: Web page to show file directory
Apr 25, 2012 02:45 PM|LINK
I will check that tonight when I return home and let you know asap... I beleive it was line 20...
Thanks!