locked
Getting the application path for a window application RRS feed

  • Question

  • User1461323171 posted

    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,

    Friday, July 20, 2012 7:31 AM

Answers

  • User271290576 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 20, 2012 9:37 AM

All replies

  • User271290576 posted

    Hello,

    Use Application.StartupPath 

    Friday, July 20, 2012 7:43 AM
  • User1461323171 posted

    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

    Friday, July 20, 2012 7:49 AM
  • User271290576 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 20, 2012 9:37 AM
  • User1461323171 posted

    Thank you Yogi !

    Monday, July 23, 2012 12:41 AM