Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access through c# code a chm file stored inside a folder which resides parallel to /bin folder of my C# windows application in Visual Studio 2005. I don't want to give full path like c:\\Program Files\\..\\. It should be like Application.Startup which leads to debug folder of our application. Please advice.
Posted
Updated 23-Jan-11 18:43pm
v4

XML
Dear Freind,
   Try the follwoing code it may help you out to get the .exe path from code
 FilePath.Value = Environment.CurrentDirectory+"\tblTestMap.txt"
this command lead you to executable path and just come out one level down by String class inbuild methods :)
Thanks,
Ambesha
 
Share this answer
 
v2
Thanks, its working and purpose is solved but still I want to know that as per your provided command we reached to executable location but /bin directory is still one level down from it. Can we access any folder which lies on the level of bin folder. Since Just for knowledge sake.
 
Share this answer
 
You're absolutely right that you don't want to use absolute path. Under no circumstances you should. For help files, the best way to locate them relative to the directory of the main module of the entry assembly of your application (which you probably indent to do).

You can find you binary path like this:

C#
string binaryPath =
     System.IO.Path.GetDirectoryName(
         System.Reflection.Assembly.GetEntryAssembly().Location);


(By the way, PrivateBinPath (referred to in other answer) is 100% irrelevant to this. This string shows a list of directories where you put private assemblies. Probably, you don't have any, then PrivateBinPath will return null. It would be pretty difficult to find anything relative to null string :) )

--SA
 
Share this answer
 
v2
Comments
Sandeep Mewara 24-Jan-11 1:25am    
Good answer, rightly pointed out! 5!
Espen Harlinn 6-Feb-11 14:53pm    
Good naswer, a 5
Sergey Alexandrovich Kryukov 6-Feb-11 18:41pm    
Thank you, Espen.
It should be a very populate technique, I don't know why it is not.
Probably because people often mix up three things: a module (main module of the entry assembly), assembly name and name space.
--SA
Lets, say if you are currently at C:/fakepath/MyProject/Modules/ folder.
Bin folder is at location: C:/fakepath/MyProject/bin/
CHM file in a folder at location: C:/fakepath/MyProject/HelpFiles/

Then try something like:
"../HelpFiles/ABC.CHM"

You just need to go at parent folder level and then move to the desired path. Make sure you have access to that folder though.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Jan-11 1:12am    
Sorry, Sandeep,
You probably do two mistakes. 1) You should not assume working directory is the same as assembly location (main module of entry assembly; if you start same application from different location, it does not work; you need this location; 2) you do not provide a method of finding executable location. Please see my answer.
You can still fix yours.
--SA
Sandeep Mewara 24-Jan-11 1:25am    
Nice catch. Thanks sir!
My bad, I was just thinking from a hosted website prospective.

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