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