I have this code in my asp.net app:
String appPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath);
String path = appPath + "\\Database\\SAMPLE.BIN";
I want to movie it to a class library, which then will be referenced by multiple projects.
The thing is that HttpContext.Current.Request.ApplicationPath
is referencing the running app and not the class lib.
How do I put the SAMPLE.BIN
inside the class lib, so that I don't have to duplicate it in all referencing projects?
EDIT:
At the end I need to be able to:
myobject.DatabasePath = appRoot + "\\Database\\SAMPLE.BIN";
You have 2 choices:
Either you pass the value as a parameter to your new library:
public class MyNewLibrary {
private string _path { get; set; }
public MyNewLibrary(string path)
{
this.path = path;
}
}
or you import the System.Web
reference and use the HttpContext
at will.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.