It works fine for a web application, but its not showing ".xml" file in windows application instead it points out to "C:\Users\Administrator\Documents\Visual Studio 2008\Projects\MyClass\WindowsFormsApplication1\bin\Debug" folder.
Please suggest me the possible way to find the dbdetails.xml in windows application, which should also work with web application
karthik_9
Member
2 Points
5 Posts
Getting the application path for a window application
Jul 20, 2012 11:31 AM|LINK
I want to create a way to retrieve application path for windows and for web application
I tried like this in a class library
public class Class1
{
public string getPath()
{
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath("~\\dbdetails.xml");
}
else
{
return Environment.CurrentDirectory;
}
}
}
It works fine for a web application, but its not showing ".xml" file in windows application instead it points out to "C:\Users\Administrator\Documents\Visual Studio 2008\Projects\MyClass\WindowsFormsApplication1\bin\Debug" folder.
Please suggest me the possible way to find the dbdetails.xml in windows application, which should also work with web application
Thanks,
YogiBirajdar
Member
146 Points
49 Posts
Re: Getting the application path for a window application
Jul 20, 2012 11:43 AM|LINK
Hello,
Use Application.StartupPath
Yogi
Please select "Mark as Answer" if my post solve your problem.
karthik_9
Member
2 Points
5 Posts
Re: Getting the application path for a window application
Jul 20, 2012 11:49 AM|LINK
I've tried that too..
return Application.StartupPath;
Its showing C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\9.0, but i need the path to dbdetails.xml file ..
If you have any, please give the usage
YogiBirajdar
Member
146 Points
49 Posts
Re: Getting the application path for a window application
Jul 20, 2012 01:37 PM|LINK
Hello,
At my end, Application.StartupPath gives me path of debug folder.
I assume your XML file will be located at debug folder, you can simply append your file name to this startup path.
Yogi
Please select "Mark as Answer" if my post solve your problem.
karthik_9
Member
2 Points
5 Posts
Re: Getting the application path for a window application
Jul 23, 2012 04:41 AM|LINK
Thank you Yogi !