Thursday, July 4, 2013

c# console application relative path

Here is the one of the common requirement i am going to explain.

I have a requirement to create a console application in that exe file should read input from xml file.

After developing that application i hardcoded and it is working fine in Dev box.

Now, when we move the exe file to production it is failing because of the path not found issue.

After that i changed the code to read file from exe file loaction with an absolute path.

Here is the peace of code for that

 string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();

In the above code String Path will get the location of the exe file where ever it is irrespective of the folder or environment.

Thank you !!

No comments:

Post a Comment