display files in a directory on a .net web page

G

Guest

Hi just wondering a good way to display all files in a directory on a server
and have them selectable to be opened by the client machine. These files
change from time to time so would not want to hard code in the link and file
names as part of the hyperlink. Also would want to launch a new page so
would use the Target="_blank"
 
J

Joey

I did this, and it worked well for us. I created an asp:Table and then
in the page load I programmatically added columns and rows...after
parsing a directory listing of the files. The end result is a nice
table with the file name, date modified, download link, etc. Also, it
is a good idea to store the files outside of the website and have the
app (ASPNET user) "go get" the file when the user clicks the download
link. I did this with a querystring and a separate (download) page.
That way, users cannot just type the file name and download.
 
G

Guest

Add a datalist, or datagrid in the page with a hyperlink inside

DirectoryInfo dire = new DirectoryInfo(sVirtualFolder);
FileInfo[] files = dire.GetFiles("*.*"); // mark of files

DataList.DataSource = files;
DataList.DataBind();

Happy programming
 
G

Guest

ok thanks for the information, not upgrading to 2.0 for awhile but nice to
know about its' features.
 
G

Guest

ok thanks I think this is what I was looking for.
--
Paul G
Software engineer.


Albert Pascual said:
Add a datalist, or datagrid in the page with a hyperlink inside

DirectoryInfo dire = new DirectoryInfo(sVirtualFolder);
FileInfo[] files = dire.GetFiles("*.*"); // mark of files

DataList.DataSource = files;
DataList.DataBind();

Happy programming


Paul said:
Hi just wondering a good way to display all files in a directory on a server
and have them selectable to be opened by the client machine. These files
change from time to time so would not want to hard code in the link and file
names as part of the hyperlink. Also would want to launch a new page so
would use the Target="_blank"
 
J

Joey

I used to do this, until we needed other information, like file name,
date modified, etc...
 
G

Guest

this seems to cause an error on the getfiles as it is on a different server.
The error is unkown user name or bad password loging in. I am able to get to
the server with windows explorer without a username and password, guess it
may be using domain information. Anyhow just if any ideas? Thanks.
 
J

Joey

The app will access the files as the ASPNET user, and it will not use
your account. Make sure the ASPNET account has the neccessary
permissions.
 
G

Guest

thanks, I do not know much about networks but wondering if I may need to add
the aspnet user to the domain or if there is a way I can have the .net
application use my windows authentication info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top