Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all...

If I know the folder name of an unknown root directory, then how can I access the files in that folder from a C# windows application. Please give me an answer..

Thanks in Advance.
Posted
Comments
Rajesh Anuhya 19-Mar-12 10:50am    
look like , real client requirement ;-)
--RA
Venkat_C6 19-Mar-12 10:53am    
Hey I can't understand what u r saying
OriginalGriff 19-Mar-12 11:01am    
I think that means that he can't work out what you are saying either.

Use the "Improve question" widget to edit your question and provide better information.
Rajesh Anuhya 19-Mar-12 11:03am    
Normally clients asks these type of silly requirements, how can you find the root directory using a folder name?
--RA
Venkat_C6 19-Mar-12 11:04am    
U r right.... I think its impossible....

1 solution

There is no such thing as "Unknown root directory". You always have some root: the root of each volume on the system. You can get all logical drives using System.IO.DriveInfo.GetDrives and the root directory of each using System.IO.DriveInfo.GetDrives.RootDirectory, please see:
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.rootdirectory.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx[^].

Now, let me tell you that for ASP.NET it makes no sense at all, anyway. Where do you want to search for directory? On client side? A Web application does not have access to the client side. On server side? A Web application can access only the directories relative to the root path of the site.

So, on the server side, your real root is the one returned as Server.MapPath("~/"); please see:
http://msdn.microsoft.com/en-us/library/ms178116.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^].

There is nothing else you can do. Anything else is not accessible by your Web application.

—SA
 
Share this answer
 
Comments
Chetan Patel 20-Mar-12 0:32am    
This is proper answer, you may resolve your issue with this hint.
Sergey Alexandrovich Kryukov 20-Mar-12 1:09am    
Thank you, Chetan.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900