|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading files in a pages directoryHi,
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 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 }
Other interesting topics
Building other sln (to build references)
User control accessing outside control SDK VS RUNTIME LIBRARY Postback,Master page,User control problem Textbox in User Control error -does not exist in current context SqlDataSource Datasource doesn't generate data GridView: Calculated Field Password Validation Hot to handle "Directory not found" from ASP.NET? |
|||||||||||||||||||||||