what is alternative of “HttpContext.Current.Server.MapPath” in Windows application, which is used in web application. What should I use in windows application to access a file.
[EDIT]
What is alternate of this in window application?
reader = XmlReader.Create(
@"D:\EnviroTrack\EnviroTracker.Web\TestDevice\Data.xml", settings);
Please suggest
You can use the normal Path methods.
MapPathhelps convert the virtual path to the physical path on the web server. There’s no need for this conversion in winforms. You may be looking for Assembly.GetExecutingAssembly().Location which returns the location of the assembly being executed.Edit – Your updated question should work on in a Winform.
XmlReader.Create has quite a few overloads, one of them is
(string, XmlReaderSettings). This is the overload you’re using in your question. You can use the same method, but different directory if you like.To get the directory of the executing assembly, you can use AppDomain.CurrentDomain.BaseDirectory. So it could be something like this: