Relative path to absolute path in C#?

前端 未结 8 2045
难免孤独
难免孤独 2020-12-02 14:14

I have xml files that contain href file paths to images (e.g. \"....\\images\\image.jpg\"). The hrefs contain relative paths. Now, I need to extract the hrefs to the images

相关标签:
8条回答
  • 2020-12-02 14:47

    Take a look at Path.Combine http://msdn.microsoft.com/en-us/library/fyy7a5kt.aspx

    0 讨论(0)
  • 2020-12-02 14:48

    You can use Path.Combine with the "base" path, then GetFullPath on the results.

    string absPathContainingHrefs = GetAbsolutePath(); // Get the "base" path
    string fullPath = Path.Combine(absPathContainingHrefs, @"..\..\images\image.jpg");
    fullPath = Path.GetFullPath(fullPath);  // Will turn the above into a proper abs path
    
    0 讨论(0)
提交回复
热议问题