Solved

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

Posted on 2004-03-30
6
162 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now