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.