This method will return a execution path of either web application or Windows application, Depend on from where we calling.
Code Snippet
- /// <summary>
- /// This method will retunrns the execution path of our application.
- /// This method returns execution path for web application as well as windows service.
- /// </summary>
- /// <returns>Returns <see cref="System.String"/> value.</returns>
- public static string GetExecutionPath()
- {
- string ExecutionPath = "";
- try
- {
- ExecutionPath = System.Web.HttpContext.Current.Server.MapPath("ServiceConfig.xml");
- }
- catch
- {
- }
- if (ExecutionPath == "")
- {
- ExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- }
- try
- {
- string strExeName = FileSystem.Dir(ExecutionPath, 0);
- string FilePath = Path.GetFullPath(ExecutionPath.Substring(0, (ExecutionPath.Length - strExeName.Length)));
- return FilePath;
- }
- catch
- {
- throw;
- }
- }
While “ServiceConfig.xml” is a configuration file kept in root of web application and windows application.
0 comments:
Post a Comment