0

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";
4

1 回答 1

0

您有 2 个选择:

要么将值作为参数传递给新库:

public class MyNewLibrary {
  private string _path { get; set; }

  public MyNewLibrary(string path)
  {
      this.path = path;
  }
}

或者您导入System.Web参考并随意使用HttpContext

于 2012-12-05T14:37:52.563 回答