Solved

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

Posted on 2004-03-30
6
165 Views
Last Modified: 2010-04-15
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 & "\"
0
Comment
Question by:bhchng
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
AdrianJMartin earned 25 total points
ID: 10723317

      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.

0
 

Assisted Solution

by:dotnet_programmer
dotnet_programmer earned 25 total points
ID: 10723387
DirectoryInfo currentDirectory;
string strPath;
string strTopFolder;
strPath = @"../..";

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

0
 

Expert Comment

by:dotnet_programmer
ID: 10723407
make sure to include "using System.IO" in your cs file.
0
 

Expert Comment

by:dotnet_programmer
ID: 10723420
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question