I have a web application thet has a number of class library projects. Some example code below.
public static class LenderBL
{
static string LenderXml { get { return "MyPathHere"; } }
public static LenderColl GetLenders()
{
var serializer = new XmlSerializer(typeof(LenderColl));
using (XmlReader reader = XmlReader.Create(LenderXml))
{
return (LenderColl)serializer.Deserialize(reader);
}
}
}
I would normally use Server.MapPath to get the path for the property LenderXml, but when I use it in a class library is returns the path of the parent solution, not that of the class library project.
Is there a way of getting the path for the class libary project itself?
Thanks in advance.
Because the MapPath method maps a path regardless of whether the specified directories currently exist, you can use the MapPath method to map a path to a physical directory structure, and then pass that path to a component that creates the specified directory or file on the server.
Right-click on the solution in Solution Explorer and select Add > New Project. On the Add a new project page, enter library in the search box. Choose C# or Visual Basic from the Language list, and then choose All platforms from the Platform list. Choose the Class Library template, and then choose Next.
As I can understand you need the current assembly location
static public string CurrentAssemblyDirectory()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With