473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Start up directory for my dll

I wrote a complied c# class (SpulClass). In that class I use this to
get the directory it resides in..

System.IO.Directory.GetCurrentDirectory();

When I call this this class (dll) from a c# windows application
this....
System.IO.Directory.GetCurrentDirectory(); returns the correct path
(C:\Roto\Work\MyProject)

When I call this this class (dll) from a c# web service this....
System.IO.Directory.GetCurrentDirectory(); returns the incorrect path
(C:\Windows\System32)
the code...
System.IO.Directory.GetCurrentDirectory(); is in the dll, not the web
app. Why is this doing this? and more importantly, what should I put
in my dll such that the correct path is returned wether the dll is
called from a Web service, Desktop app or what ever.
Thanks in advance
-Roto-

Jan 11 '07 #1
4 5009
Roto,

Current directory i a property of the OS and has nothing to do with the
location where the dll has been loaded from or exe's startup path. I don't
know which one you want to get, but take a look at Assembly class properties
there is a proeprty for the DLL phisical location. For Windows forms
application you can use Application.StartupPath property for getting exe's
startup location. where for web application you can use path mapping
mechanism to get similar information.

--
HTH
Stoitcho Goutsev (100)

<ro****@earthlink.netwrote in message
news:11**********************@o58g2000hsb.googlegr oups.com...
>I wrote a complied c# class (SpulClass). In that class I use this to
get the directory it resides in..

System.IO.Directory.GetCurrentDirectory();

When I call this this class (dll) from a c# windows application
this....
System.IO.Directory.GetCurrentDirectory(); returns the correct path
(C:\Roto\Work\MyProject)

When I call this this class (dll) from a c# web service this....
System.IO.Directory.GetCurrentDirectory(); returns the incorrect path
(C:\Windows\System32)
the code...
System.IO.Directory.GetCurrentDirectory(); is in the dll, not the web
app. Why is this doing this? and more importantly, what should I put
in my dll such that the correct path is returned wether the dll is
called from a Web service, Desktop app or what ever.
Thanks in advance
-Roto-

Jan 11 '07 #2
<ro****@earthlink.netwrote...
When I call this this class (dll) from a c# web service this....
System.IO.Directory.GetCurrentDirectory(); returns the incorrect path
(C:\Windows\System32)

the code...
System.IO.Directory.GetCurrentDirectory(); is in the dll, not the web
app. Why is this doing this? and more importantly, what should I put
in my dll such that the correct path is returned wether the dll is
called from a Web service, Desktop app or what ever.

Services run from the System32 folder. DLLs are run within the context of
the calling application. In order for your DLL to determine it's own path,
you'll need to use the GetModuleFileName() API:

http://www.pinvoke.net/default.aspx/...eFileName.html

I use this in my Delphi DLLs and works great. However, you need to pass in
the HInstance of the DLL module itself in the first parameter, which I've
yet to find in C#. IntPtr.Zero in the above example will return the calling
application path. Maybe someone else can inform us of how to get the
instance handle within a DLL project for this to work.

--
Thanks,
Jon E. Scott
Blue Orb Software
http://www.blueorbsoft.com
Jan 11 '07 #3
Hi,

<ro****@earthlink.netwrote in message
news:11**********************@o58g2000hsb.googlegr oups.com...

| the code...
| System.IO.Directory.GetCurrentDirectory(); is in the dll, not the web
| app. Why is this doing this? and more importantly, what should I put
| in my dll such that the correct path is returned wether the dll is
| called from a Web service, Desktop app or what ever.

First of all a dll does not start-up, some other executable does and then
the dll is loaded either by the framework or by code. In case you want to
know where the dll was loaded from (in case you have a config file in the
same dir for example) you have to use Assembly.CodeBase. You have to use it
from inside the dll though. Usually you go by

Asssembly.GetExecutingAssembly().CodeBase
--
Ignacio Machin
machin AT laceupsolutions com
Jan 11 '07 #4
Try this (not tested, but should work)

Assembly assm = Assembly.GetExecutingAssembly();
string location = assm.Location;
string assemlyPath = Path.GetDirectoryName(location); // This is the
directory where your DLL reside.

NOTE: If the asembly is in the GAC, this code will return the GAC path
("C:\WINDOWS\assembly").

Hope it helps

Boaz Ben-Porat
Milestone Systems A/S
Denmark

<ro****@earthlink.netskrev i en meddelelse
news:11**********************@o58g2000hsb.googlegr oups.com...
>I wrote a complied c# class (SpulClass). In that class I use this to
get the directory it resides in..

System.IO.Directory.GetCurrentDirectory();

When I call this this class (dll) from a c# windows application
this....
System.IO.Directory.GetCurrentDirectory(); returns the correct path
(C:\Roto\Work\MyProject)

When I call this this class (dll) from a c# web service this....
System.IO.Directory.GetCurrentDirectory(); returns the incorrect path
(C:\Windows\System32)
the code...
System.IO.Directory.GetCurrentDirectory(); is in the dll, not the web
app. Why is this doing this? and more importantly, what should I put
in my dll such that the correct path is returned wether the dll is
called from a Web service, Desktop app or what ever.
Thanks in advance
-Roto-

Jan 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Barry Cannon | last post by:
I have developed an Access application and am attempting to add a button to one form that will run our Work Order system. The Work Order system is normally started from an icon on the desktop. ...
0
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated ...
5
by: Bruce Schechter | last post by:
I just started to develop an ASP.NET application in vs.net 2003 . But each time I try to execute the application (which is basically empty so far), I get a dialog box titled "Microsoft Development...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
18
by: Juan Gil | last post by:
I have a problem with this. I installed it in my computer to modify it, but when I try to save the configuration file(xml file) the server returned an error that say that I dont have permissions to...
5
by: DraguVaso | last post by:
Hi, I want my appliation to Run a Shortcut on my Desktop. This should be done regardless the fact if the Shortcut is in the All Users\Desktop or MyProfile\Desktop and regardless the version of...
0
by: Rich | last post by:
I have an ASP.NET application "Modeler" that I adapted from ibuyspy. I worked fine under ASP.NET 1.1 & Visual Studio 2003. I recently installed ASP.NET 2.0 & Visual Studio 2005 Pro. After...
3
by: rmlucero | last post by:
What I am looking to do is to launch an executable program in VB that will also point to the "start in" directory. On the Shortcut, the Target is the command line and the Start in is the...
2
by: Miro | last post by:
In VB-2003, I was wondering if someone can point me in the right direction: Lets say the user has a shortcut on his desktop to your app. 1. Is there any way to capture what the "Start In"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.