Click here to Skip to main content
11,705,610 members (52,589 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows WPF VB.NET
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 7-Mar-13 0:22am
Code-Hunt7.1K
Comments
Sampath Sridhar at 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>
ryanb31 at 7-Mar-13 7:04am
   
You should post that as the solution.
Snehasish Nandy at 7-Mar-13 6:50am
   
got it..thanks...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Posting it to pop it our of unanswered list. OP commented that it is resolved now.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

Solution 4

 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

Dim fName As String = MyPath() & "\CnSetting.cn"
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 229
1 Sergey Alexandrovich Kryukov 100
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2015
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