Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#
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 23-Jan-11 19:39pm
sk saini5.6K
Edited 23-Jan-11 19:43pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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:
 
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 Smile | :) )
 
--SA
  Permalink  
v2
Comments
Sandeep Mewara at 24-Jan-11 1:25am
   
Good answer, rightly pointed out! 5!
Espen Harlinn at 6-Feb-11 14:53pm
   
Good naswer, a 5
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
SAKryukov at 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 at 24-Jan-11 1:25am
   
Nice catch. Thanks sir!
My bad, I was just thinking from a hosted website prospective.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
v2

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

  Print Answers RSS
0 Marcin Kozub 275
1 OriginalGriff 264
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 17 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100