Reputation: 575
I have a ClassLibrary Project which is my business layer - Demo.Business
For this class library,
I have folder in the class library as below
TRT
|
TRT.cs
TRTDetails.cs
TRTFiles(Folder)
|
**TRTFile.txt**
In TRT.cs class i have a method
public void UpdateDetails()
{
var typeSeq = from val in TRTDetails.Read**(@"TRTFile.txt")**
}
Now i have added reference of this class library "Demo.Business.dll" to my console application - "DemoProcess.exe". In the above Console Application I am calling the method "UpdateDetails()" as follows:
public void CallMethod()
{
UpdateDetails();
}
How can I specify the path of the file "TRTFile.txt" in the method "UpdateDetails()" in class library?
I tried using System.IO.Path.GetDirectoryName
(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Which always gives the path of executing application. i.e
C:\\Projects\\Demo.Process\\bin\\Debug
How can i get the path as
C:\\Projects\\Demo.Business\\TRT\\TRTFiles............
Upvotes: 0
Views: 87
Reputation: 1774
There are two ways to do this:
I.
This can be done using relative path. If your's dll
is also situated in Debug
folder, the following path = @"..\..\..\Demo.Business\TRT\TRTFiles\"
will do the work.
First ..\
will get us to C:\\Projects\\Demo.Process\\bin\\
.
Second ..\
will get us to C:\\Projects\\Demo.Process\\
.
Third ..\
will get us to C:\\Projects\\
.
II. Or by using classes used for writing visual studio extensions (Extensibility, EnvDTE namespaces, etc.), they provide functionality to get all information about your project and it's content. But it's complicated.
Upvotes: 1