Sponsored Ad

Wednesday, January 6, 2010

Get Execution Path Shared by Web application and Windows application Using c#

This method will return a execution path of either web application or Windows application, Depend on from where we calling.

 

Code Snippet
  1. /// <summary>
  2.     /// This method will retunrns the execution path of our application.
  3.     /// This method returns execution path for web application as well as windows service.
  4.     /// </summary>
  5.     /// <returns>Returns <see cref="System.String"/> value.</returns>
  6.     public static string GetExecutionPath()
  7.     {
  8.         string ExecutionPath = "";
  9.         try
  10.         {
  11.             ExecutionPath = System.Web.HttpContext.Current.Server.MapPath("ServiceConfig.xml");
  12.         }
  13.         catch
  14.         {
  15.         }
  16.         if (ExecutionPath == "")
  17.         {
  18.             ExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  19.         }
  20.         try
  21.         {
  22.             string strExeName = FileSystem.Dir(ExecutionPath, 0);
  23.             string FilePath = Path.GetFullPath(ExecutionPath.Substring(0, (ExecutionPath.Length - strExeName.Length)));
  24.  
  25.             return FilePath;
  26.         }
  27.         catch
  28.         {
  29.             throw;
  30.         }
  31.     }

While “ServiceConfig.xml” is a configuration file kept in root of web application and windows application.

0 comments:

Post a Comment

Sponsored Ad

More Related Articles

Website Update

Followers