C # Downloading an xml file from the current directory?

I use the line below in my C # winform application, this works fine, but sometimes, if the program starts from the command line, I get an error that the config.xml file could not be found. This is because the "working directory" is different (I think), I need to say "load config.xml from the current directory", how would I do it?

 docXML.Load("config.xml"); 

Thanks Jonathan

+4
source share
2 answers
 string fileName = Path.Combine(Application.StartupPath, "config.xml"); 
+7
source
  string Path = ""; string Filename = ConfigurationManager.AppSettings("Filename"); 

to download from the current directory

  Path = System.Web.HttpContext.Current.Server.MapPath(Filename); 

to download from the base directory

  Path = AppDomain.CurrentDomain.BaseDirectory + Filename; 
+3
source

Source: https://habr.com/ru/post/1305168/


All Articles