Reading files in a pages directory

F

farseer

Hi,
I am storing certain files in the same directory as an asp page. I'd
like for that page to be able to read read the names of the files in
that directory with a certain extension and create a hyperlink to them.
How can i do this.

as an example...
let's say my page resides at /mysite/dir1/default.aspx.
now in /mysite/dir1 are the files pic.jpg, pic1.jpg, pic2.jpg.

when a users goes to www.mysite.com/dir1/default.aspx, i'd like the
page to list links to those jpg files.

Using VS 2005, when i am debugging, it seems that the code is not
reading from the directory that the page lives, but rather from the
Visual Studio's installation directory.

thanks for any assistance
 
T

Tasos Vogiatzoglou

First of all you should take care about the permissions of the account
that is executing your page. Apart from that, you can do the following

:

string pagePath = Server.MapPath(Page.Request.FilePath);
DirectoryInfo dirInfo = new
DirectoryInfo(Path.GetDirectoryName(pagePath));
FileInfo[] nfos = dirInfo.GetFiles("*.jpg");
foreach (FileInfo inf in nfos) {
//show the files
}
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top