How to find the Current Path, in Windows Application
-
Hi all, i have developed an windows application where in which, i want the current path where the project dll is residing, i mean, here I'm refering to an XML file in the user control like(@"..\\..\xmlfile.xml"); but this path is taking to the application path[Two Up] --after i built this application to an .exe and excute its giving FileNotFound Excpetion.so, i want the current path where the dll is residing, Please help me. Prashanth
-
Hi all, i have developed an windows application where in which, i want the current path where the project dll is residing, i mean, here I'm refering to an XML file in the user control like(@"..\\..\xmlfile.xml"); but this path is taking to the application path[Two Up] --after i built this application to an .exe and excute its giving FileNotFound Excpetion.so, i want the current path where the dll is residing, Please help me. Prashanth
-
Hi all, i have developed an windows application where in which, i want the current path where the project dll is residing, i mean, here I'm refering to an XML file in the user control like(@"..\\..\xmlfile.xml"); but this path is taking to the application path[Two Up] --after i built this application to an .exe and excute its giving FileNotFound Excpetion.so, i want the current path where the dll is residing, Please help me. Prashanth
Take a look at the
Application.StartupPath
property.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Take a look at the
Application.StartupPath
property.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Please be aware that
Application.StartupPath
returns the path of the application that started the executable. See: http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx This path is not necessaraly YOUR application. If someone creates a laucncher for your application, if would return the path to their application not yours and also does not include the executable name. The better method would be:string path = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
Hope this helps.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog
-
Take a look at the
Application.StartupPath
property.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Application.StartUpPath will not work for projects having output type as 'class library' use Environment.CurrentDirectory instead
Pakistani Memon Prime Minister Post Meridian
-
Application.StartUpPath will not work for projects having output type as 'class library' use Environment.CurrentDirectory instead
Pakistani Memon Prime Minister Post Meridian
A similar problem exists when using
Environment.CurrentDirectory
as the current directory is not necessarily the folder in which your application resides. You can test this yourself by creating a console application containing the following code:public static void Main(string[] args) { Console.WriteLine("Current Directory: " + Environment.CurrentDirectory.ToString() ); Console.WriteLine("Press any key to continue..."); Console.ReadKey( true ); }
Now if you run the code, it does as you would expect. But if you open your applications folder in explorer then right-click and 'create a shortcut', you can edit the properties of the shortcut and change the 'Start in' parameter to 'C:\'. When you then run the application using the shortcut, the current directory is set to 'C:\' and not that of your application. Please see my previous post for the correct method.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog