Search This Blog

Friday, April 5, 2013

C# Code To Get The Folder Path Of A Executable

Following Code snippet will return the folder path of the current running application.
 public static string GetExePath()
 {
     string strPath = Application.ExecutablePath;
     string strBackSlash = @"\";
     int nPos = -1;
     if ((nPos = strPath.LastIndexOf(strBackSlash)) > -1)
     {
         strPath = strPath.Substring(0, nPos + strBackSlash.Length);
     }
     return strPath;
 }
 
 
Usage:
 string strpath = GetExePath();
 MessageBox.Show(strpath);

Screenshot:

 

No comments:

Post a Comment