添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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
method 1:
// const string TemplatePath = "~/HTMLPage.htm";//error could find path
// //var reader = new StreamReader(TemplatePath).ReadToEnd();
method 2;
//// 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
any idea how to specify the path help me.
when you run you console app in run from debug/ release folder inside bin folder. to get access your html file you have to put the file in debug/ or release folder & then you can use
string fileName = "HTMLPage.htm";
string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(folder, fileName);
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.
  •