Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ...

in vs2008 (C#):

I have :
1. a main project (windows app)
2. WCF Library
3. WCF Host
4. WCF Client (Windows app)

for testing my service with created client, I call my client form in my main proj and after getting the input requirement of service by this form , I start making response of service by calling my service contract method .

in this service I need to create a proper connection string with recieved parameter for request and I need my application startup path (D:\myProj.dll) to get access to an exe file , Unfortunately after using diffrent kinds of codes that return this path, exactly at point of calling my service, I get another paths I don't need (myproj,bin.debug or c:\programfiles\visual studio9\common7\IDE) can U help me ?

for additional info I have to say that I added this path by a command to post-build event of my service library and client.


plz help me to get access to this path (startup path of my project -> D:\myProj.dll)

thank you in advance
Posted

1 solution

So, start-up path, not "adr", right?

If you have some code in some assembly, this call can give you the executing assembly:
C#
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
Naturally, you can get the location of any other assembly, for example, the entry assembly, using System.Reflection.Assembly.GetEntryAssembly(); etc. Basically, this way you find a location of a main executable module of some assembly, which is a file. (An assembly itself does not have to be a single file, even though VS only support creation of single-module assemblies; the file is also a module, not an assembly.)

Now, you can extract the directory path:
C#
string exePath = System.IO.Path.GetDirectoryName(assemblyLocation);


Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.path.aspx[^].

I don't understand how can you "get access to an exe file", and how is this related to WCF, but it looks like this is your problem. :-)

—SA
 
Share this answer
 
v2
Comments
Maciej Los 21-May-12 17:58pm    
Wow! A 5!
Sergey Alexandrovich Kryukov 21-May-12 18:20pm    
Thank you.
--SA
Wonde Tadesse 21-May-12 20:08pm    
5+
Sergey Alexandrovich Kryukov 21-May-12 21:03pm    
Thank you, Wonde.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900