i am using console application inside asp.net application to send a html template through
mail.but it will display the error message could not find part of the path.i am using httpcontext
to find the path is there any other way to find the path without using httpcontext.my code is
//// StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/HTMLPage.htm"));error
i am using conosole application as a seperate project inside asp.net application.if anyone have
The question is not clear. In an ASP.NET code-behind code, you should of course use
MapPath
. For your separate application you execute on the server, this function does not mean anything certain. You can find the path where the currently running application is located this way:
string
exeDir = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location;
By the way, there are many other ways to find this path, but some of them are not universal, they work incorrectly for some ways of hosting the application, etc. The method I show is universally correct.
The following line of code will work.
Var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
It will give you hosting physical path. You can concatenate with sub folder further.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
string fileName = "HTMLPage.htm";
string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(folder, fileName);