Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

i wrote the below code to get the path for a image

p = Path.GetFullPath("Images\Question-icon.png")

its returning me the path as
C:\Users\501013\Desktop\Shortcuts\Shortcuts\bin\Debug\Images\Question-icon.png

but my actual path is
C:\Users\501013\Desktop\Shortcuts\Shortcuts\Images\Question-icon.png

Please tell me how to get the actual path

Thank you
Posted
Comments
Sampath Sridhar 7-Mar-13 6:35am    
There could be duplicate image in Debug folder.
Please check and delete that.
Otherwise check as follows:
<pre lang="c#"> p = Path.GetFullPath("..\..\Images\Question-icon.png")</pre>
ZurdoDev 7-Mar-13 7:04am    
You should post that as the solution.
[no name] 7-Mar-13 6:50am    
got it..thanks...

Posting it to pop it our of unanswered list. OP commented that it is resolved now.
 
Share this answer
 
It's giving you the Debug path because that's the current directory as far as your running .EXE is concerned. It's NOT going out and actually trying to find the file for you. It just manipluates path spec's without evern touching the file system or looking at any files to see if they exist or not.
 
Share this answer
 
VB
 Public Function MyPath() As String
    Dim sPath As String = Application.ExecutablePath
    sPath = System.IO.Path.GetDirectoryName(sPath)
    If sPath.EndsWith("\bin\Debug") Then
        sPath = sPath.Substring(0, Len(sPath) - 10)
    ElseIf sPath.EndsWith("\bin\Release") Then
        sPath = sPath.Substring(0, Len(sPath) - 12)
    End If
    Return sPath
End Function


using Mypath

VB
Dim fName As String = MyPath() & "\CnSetting.cn"
 
Share this answer
 

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