I am trying to select all the files from a folder in my website and store them in a collection. The problem is that when I run the website it is not selecting the folder in my website:
This is the basic structure: [Root Folder] --> [FilesFolder]
Here is the code I am using:
DirectoryInfo dir = new DirectoryInfo("FilesFolder");
But it is showing this at runtime as the location of the folder:
C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\FileUpload开发者_JAVA百科s
Is there a way to select the folder relative to the root of the website?
I am using C# with ASP.NET 3.5
You need to provide the full path to the web site when accessing it through the directory as in:
new DirectoryInfo("c:\inetpub\wwwroot\RootFolder\FilesFolder")
If you are trying to do this within an ASP.NET web site code, you can use Server.MapPath as in:
string path = Server.MapPath("~/FilesFolder");
Use:
Server.MapPath("~/FilesFolder");
More about it here: http://msdn.microsoft.com/en-us/library/ms178116.aspx
精彩评论