How to get the current directory on a class library? How to get the current directory on a class library? asp.net asp.net

How to get the current directory on a class library?


This should work -

string assemblyFile = (    new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;


The below code worked for me to get the physical path of the Images folder in-class library file.

string fullFilePath = Path.Combine((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath.Split(new string[] { "/bin" }, StringSplitOptions.None)[0]                          , "@/Images/test.png");

I hope, it will help someone.


Old Question, but answering for new viewers.Simply access the file. I've tried multiple methods by setting the directory dynamically, yet no positive result.But on the flip side I see that it automatically accesses the files in its directory/sub-directories, without explicitly calling any methods to get current directory.

[My Case]I had to access a config file stored together in with a class library, and I could access it directly without specifying or setting the address.