display files in a directory on a .net web page

  • Thread starter Thread starter Guest
  • Start date Start date
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"
 
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.
 
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
 
ok thanks for the information, not upgrading to 2.0 for awhile but nice to
know about its' features.
 
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"
 
I used to do this, until we needed other information, like file name,
date modified, etc...
 
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.
 
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.
 
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

Back
Top