asp.net and C # path. GetFullPath Get Superior Directory

Source: Internet
Author: User
Tags parent directory

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

Get the current directory to use Appdomain.currentdomain.basedirectory.

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

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 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 parent directory: {0}", dir);

Console.WriteLine (info);

The ancestor's parent directory that uses path to get the execution directory of the current application set

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

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

Console.WriteLine (info);

Use path to get the parent directory of the execution directory for 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 to 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 is more complex, I only know environment.currentdirectory is the current EXE path, you have to get the first level of this path calculation.
ASP tutorial. NET is relatively simple, direct ... /on the line.

If the ASP.net tutorial is Server.MapPath ("~/bg/") it is OK.

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.