ASP. NET and C # path. GetFullPath Get Parent Directory

Source: Internet
Author: User

String path = new DirectoryInfo (".. /"). fullname;//the parent directory of the current application path

You can use Appdomain.currentdomain.basedirectory to get the current directory.

Gets the parent directory of the current directory Path.GetFullPath ("..")

Code

using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.IO;

Namespace Pathtest

{

Class Program

{

static void Main (string[] args)

{

Use the AppDomain to get the execution directory of the current application set

string dir = appdomain.currentdomain.basedirectory;

string info = String.Format ("AppDomain method gets the current assembly directory: {0}", dir);

Console.WriteLine (info);

Use path to get the parent directory of the execution of the current application set

dir = Path.GetFullPath ("..");

info = String.Format ("path method gets the current assembly ancestor directory: {0}", dir); (www.111cn.net)

Console.WriteLine (info);

Use path to get the parent directory of the executing directory of the current application set

dir = Path.GetFullPath (@ "....");

info = String.Format ("path method gets the parent directory at the level of the current assembly directory: {0}", dir);

Console.WriteLine (info);

Use path to get the parent directory of the execution directory of the current application set

dir = Path.GetFullPath (@ "...");

info = String.Format ("path method gets the parent directory of the parent directory of the current assembly directory: {0}", dir);

Console.WriteLine (info);

Add the specified directory in the current assembly directory

dir = Path.GetFullPath (@ "io");

info = String.Format ("Add the specified directory in the current assembly directory: {0}", dir);

Console.WriteLine (info);

Console.read ();

}

}

}

WinForm more complex, I only know that environment.currentdirectory is the path of the current EXE, you want to get the upper level of this path calculation.
The ASP tutorial. NET is simpler and more straightforward. /On the line

If it is an ASP. Server.MapPath ("~/bg/") it is OK.
From:http://www.111cn.net/net/net/37071.htm

ASP. NET and C # path. GetFullPath Get Parent Directory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.