在代码段中获取错误 [英] Getting error in piece of code

查看:75
本文介绍了在代码段中获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



i写了下面的代码来获取图片的路径



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



它让我回到原点

C:\ Users \\ \\ 501013 \Desktop \Shortcuts \Shortcuts\\\\Debug \Images \ Question-icon.png



但我的实际路径是

C:\ Users \501013 \Desktop \Shortcuts \Shortcuts\Images\Question-icon.png



请告诉我如何获得实际路径



谢谢你

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

推荐答案

发布它弹出我们的未答复的清单。 OP评论说现在已经解决了。
Posting it to pop it our of unanswered list. OP commented that it is resolved now.


它提供了调试路径,因为就运行的.EXE而言,它是当前目录。它不会出去,实际上试图找到你的文件。它只是在没有evern触摸文件系统或查看任何文件以查看它们是否存在的情况下操纵路径规范。
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.


 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





使用Mypath





using Mypath

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


这篇关于在代码段中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆