Can i do something like this in window Application?
HttpContext.Current.Server.MapPath("Email/ForgotPassword.txt"));
This project is a web based application.
And my next project is basically a window service...
Seeking for advice.
To get the path that the Exe is running at (which is a good location to add paths like "Email"), use:
string filePath = Application.StartupPath + "\\Email\\ForgotPassword.txt";
This path is the ..\bin\debug\Email path when you run it on VS and ..\Email path when you run it after installation.
There are few alternates to do this like these to access the directory path:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
or
using System.IO;
using System.Reflection;
string path = Path.GetDirectoryName(
Assembly.GetAssembly(typeof(MyClass)).CodeBase);
you can do manipulation with the Path class like get the full path, directory name etc etc..
Check this MSDN forum thread How to get the current directory path c# winfows for application for details.
As you expecting to do windows application as like web.. It is not possible.
If you're not processing requests from ASP.NET (or more specifically, System.Web
), HttpContext.Current
will be null. So then the answer is: no, you can't do what you are asking. Perhaps:
Assembly.GetExecutingAssembly().Location
combined with methods from Path would be useful?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With