|
Application. does not work inside the class library project
Any thoughts please?
|
|
|
|
|
Assembly.ExecutionAssembly.Location.
Never re-post. Just modify your earlier post
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Hi,
This does not seem to work inside the class library project.
|
|
|
|
|
I have used it and it works. Whats the error you are getting?
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Intellisense does not recognize Assembly
|
|
|
|
|
Right click it and resolve assembly name. Thats it.
or add reference to System.Reflection
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
try
Environment.CurrentDirectory
|
|
|
|
|
Environment.CurrentDirectory gives the following path:
"C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug"
Please note the .xml file is sitting under:
C:\\Work\\Developments\\SQLchecks\\SQLchecks\\DataAccess\\text.xml
Any thoughts please?
|
|
|
|
|
Replace
SQLchecks\\bin\\Debug
with
SQLchecks\\DataAccess\\text.xml
using string functions to replace string
|
|
|
|
|
Hi,
I now get this error:
Access to the path 'C:\Documents and Settings\jodowe\Local Settings\Apps\2.0\JXW1XBXW.7LE\414E3W43.NMO\sqlc..tion_3237500c67d360be_0001.0000_06a11946b45767e8' is denied.
|
|
|
|
|
I guess the data directory is always inside the the project. Just choose to copy the file into the exe location with every build(with subpath dataaccess) in the designer. Would be reallife behaviour.
|
|
|
|
|
you can replace like this
string str = "C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug";
str=str.Substring(0,str.IndexOf("\\SQLchecks\\bin\\Debug"));
str = str + "\\DataAccess\\text.xml";
|
|
|
|
|
This following code will help you to access the file which is added to the project
Add the file into the project and then set the property as embedded file then you will be able to access with the following code. or you can add the file in the resource file and you will be able to access the file.
Assembly embeddedFile = Assembly.GetExecutingAssembly();
Stream StreamEmbeddedFile;
StreamEmbeddedFile = embeddedFile.GetManifestResourceStream ("NameSpace.Test.xml");
XmlDocument myStylesheet = new XmlDocument();
myStylesheet.Load(StreamEmbeddedFile);
Here, "NameSpace" is default namespace.
if you have any other problem on this pls let me know
Thanks
Raja.S
modified on Tuesday, August 19, 2008 7:25 AM
|
|
|
|
|
Hi Raja.S,
This code does not seem to work as I need to run it from the class inside a class library project. i.e. Assembly is not recognised in intellisense
|
|
|
|
|
You have to include "using System.Reflection;" it is available in Class Library as well. you mean to say the color of the code is not changed in the IDE that means you haven’t included the name space.
This is getting the running assembly if it is class library then class library(dll) will be loaded to the running process on the demand , when it executes the code from class library the running assembly will be the class library(dll) .
Thanks
Raja.S
|
|
|
|
|
Correction to my previous post.
I have created a windows application.
There are forms inside the windows form application project. There is a class library project too.
The .sln is in the following path:
C:\Work\Developments\SQLchecks\SQLchecks
The windows forms are inside the windows application project as below:
C:\Work\Developments\SQLchecks\SQLchecks\SQLchecks
There is a class library project called DataAccess which has classes and an xml file called Settings.xml :
C:\Work\Developments\SQLchecks\SQLchecks\DataAccess
Question:
from within a class inside the DataAccess project which is a class library project, how do I refer to the Settings.xml file which is also in the same directory?
Thanks
|
|
|
|
|
Got that !! your class library and the setting.xml in the same folder you want to access that setting.xml from the class library
simple:
using System.Reflection;
string path = Assembly.GetExecutingAssembly().Location;
path = path + "setting.xml";
let me know the result.
Thanks
Raja.S
|
|
|
|
|
This seems to be IN-correct because it returns:
"C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug\\DataAccess.dllSettings.xml"
Please note the Settings.xml file is inside C:\\Work\\Developments\\SQLchecks\\SQLchecks\\DataAccess
Where DataAccess is a classLibrary Project which sits inside a dataAccess folder.
I then modified the above code and placed "\Settings.xml"
The new error is:
Could not find a part of the path 'C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug\\DataAccess.dll\\Settings.xml'."
Any thoughts please?
|
|
|
|
|
Sorry it should be
path = path + "\\setting.xml";
this should work
Thanks
Raja.S
|
|
|
|
|
The new error is:
Could not find a part of the path 'C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug\\DataAccess.dll\\Settings.xml'."
Thanks
|
|
|
|
|
Have checked is that setting.xml is there in that path ?
can i get your hotmail id if possible we can chat ?
Thanks
Raja.S
|
|
|
|
|
hey man your getting the path with the assembly name discard assembly name from the path and put the setting.xml every thing should work fine
it should be
'C:\\Work\\Developments\\SQLchecks\\SQLchecks\\SQLchecks\\bin\\Debug\\Settings.xml'."
Thanks
Raja.S
|
|
|
|
|
Hi,
These files are present in:
C:\Work\Developments\SQLchecks\SQLchecks\DataAccess\bin\Debug
DataAccess.dll
Settings.xml
...
...
|
|
|
|
|
Find the code here
// get current path for the assembly
string path = Assembly.GetExecutingAssembly().Location;
path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path),".."));
path = path + @"\setting.xml";
Thanks
Raja.S
|
|
|
|
|
final code here
using System.IO;
using System.Reflection;
// get current path for the assembly
string path = Assembly.GetExecutingAssembly().Location;
path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path),".."));
path = path + @"\setting.xml";
pls let me know the result
Thanks
Raja.S
|
|
|
|