A more standard way to do this is to use the HttpContext.Current method:
if (HttpContext.Current == null) { // called from windows application } else { // called from web application }
Of course, using HttpContext-related materials in non-HTTP layers of your application is a design odor. It doesn't just smell => it stinks.
A more standard way is to have your code passed as an argument directly as an argument. When called from a web application, you must pass Server.MapPath("~/foo.txt") , and when you call it from a Windows application, you must pass the file name relative to the current executable.
Thus, your code should not depend on any specific HTTP data and can be used with pleasure on any platform. The responder must give him the name of the file that your code should process. The way this file is defined is platform dependent. Not responsible for your code. Do not mix duties.
source share