[Help Needed] From ASP to ASP.NET(C#)

Dear all,

Need your expertise here. I am converting a ASP code to ASP.NET(C#). I am wondering if anybody have any idea on how to convert the following ASP code ? I am trying to list the folders inside a virtual directory. Thanks a lot in advance.

ASP Code:

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.Mappath("../.."))
strTopFolder = objFolder.Path & "\"
Who is Participating?
AdrianJMartinConnect With a Mentor Commented:

      string[] dirs = System.IO.Directory.GetDirectories( Server.MapPath(@"..\.." ) ) ;
      string topFolder = dirs[0] + @"\" ;

beware the "..\.." on my system this exits the tree ie no more up dirs and a System.Web.HttpException is thrown.

dotnet_programmerConnect With a Mentor Commented:
DirectoryInfo currentDirectory;
string strPath;
string strTopFolder;
strPath = @"../..";

currentDirectory = new DirectoryInfo(strPath);
if (!currentDirectory.Exists)
     throw new ArgumentException("Directory does not exist " + strPath + ".");
     strTopFolder = Path.GetFullPath(currentDirectory.Name) + @"\";

make sure to include "using System.IO" in your cs file.
also just in case you are wondering, the @ before the quotes (i.e. @"\") tells the compiler to ignore the break characters like \ in the string. Otherwise you would get an error compiling.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.