Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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