相对路径(relativePath)是..\..\runtime\a.txt(此信息存储在xml文件中)
openFilePath d:\1\2\rumtime\save.xml
当我打开xml文件时,我要重新得到他的绝对路径
想得到:D:\1\2\runtime\a.txt
请问如何做到,多谢了
private string GetAbsolutePath(string relativePath,string openFilePath)
{
string ResultPath = "";
if(relativePath.StartsWith(@".\"))
{


}
else
{ ResultPath = relativePath;
return ResultPath;
}
return ResultPath;
}

解决方案 »

  1.   

    用Application.startUpPath可以获取启动了应用程序的可执行文件的路径.
    比如相对路径是path.txt的文件就是string startpath = Application.startUp;
    string realpath = startpah + "path.txt";realpaht就是绝对路径
    根据这个类推可以得到相对的路径的绝对路径.这个办法不知道能不能解决你的问题?
      

  2.   

    Application.StartupPath 属性  [Visual Basic]请参见
    Application 类 | Application 成员 | System.Windows.Forms 命名空间 | Application 成员(Visual J# 语法) | C++ 托管扩展编程 要求
    平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列
    .NET Framework 安全性:  
    FileIOPermission 用于获取路径。关联的枚举:FileIOPermissionAccess.PathDiscovery 
    语言
    C#C++JScriptVisual Basic全部显示
    获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
    [Visual Basic]
    Public Shared ReadOnly Property StartupPath As String
    [C#]
    public static string StartupPath {get;}
    [C++]
    public: __property static String* get_StartupPath();
    [JScript]
    public static function get StartupPath() : String;
    属性值
    启动了应用程序的可执行文件的路径。
    示例
    [Visual Basic, C#, C++] 下面的示例获取该属性并在文本框中显示其值。本示例假定 textBox1 已放置在窗体上。
    [Visual Basic] 
    Private Sub PrintStartupPath()
       textBox1.Text = "The path for the executable file that " & _
          "started the application is: " & _
          Application.StartupPath
    End Sub