Click here to Skip to main content
15,924,195 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I Have created one windows application in c#.
i have created one folder in it (i.e. folder1). In that folder (i.e folder1) i have added text file (i.e. TextFile1).

Now i have to get the path of this file i.e TextFile1 in some string variable.

How can it possible to get correct path? Please help.

my exe is in bin\debug folder. but folder1 is outside bin folder.

Thanks in advance.
Posted
Updated 15-Nov-11 0:30am
v3

Where is your application EXE reside ?
if it reside at "folder1" level. then you can get it like
C#
Application.ExecutablePath + "\Folder1\Textfile1.txt"
 
Share this answer
 
Comments
Swapnildth 15-Nov-11 6:25am    
my exe is in bin\debug folder. but folder1 is outside bin folder.
koolprasad2003 15-Nov-11 6:30am    
use Application.ExecutablePath + "..\..\Folder1\Textfile1.txt"
Swapnildth 15-Nov-11 6:38am    
above code showing like this
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.EXE..\..\Folder1\Textfile1.txt

not the correct path..
C#
string strRootDir = System.IO.
Directory.GetCurrentDirectory();
string strPath = strRootDir + "\\Folder1\\TextFile1.txt";



mark as answer if solves your problem.
 
Share this answer
 
Comments
Swapnildth 15-Nov-11 6:29am    
this code also giving bin\debug path
C#
Application.ExecutablePath + "..\..\Folder1\Textfile1.txt"<</pre>
 
Share this answer
 
Comments
Swapnildth 15-Nov-11 6:39am    
above code showing like this
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.EXE..\..\Folder1\Textfile1.txt

not the correct path..
Swapnildth 15-Nov-11 6:40am    
the correct path should be
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Folder1\Textfile1.txt

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