Convert a relative path that includes a drive letter to an absolute path for .NET file functions
问题 How can you convert a drive relative path such as D:test.xml into an absolute path that a function such as XDocument.Load() will accept. The D drive could have D:\data as its current working directory, for example, so D:test.xml would mean D:\data\test.xml . I've already tried such concoctions as D:.\test.xml . Here is the error I get for something like D:test.xml: Invalid URI: A Dos path must be rooted, for example, 'c:\' 回答1: You could use GetFullPath. For example: // should return "D:\data