本文介绍了转换文件的文件路径URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问在.NET Framework有什么方法转换路径(如C:\ whatever.txt
)到一个文件中的URI(例如文件:/// C:/whatever.txt
)
Does the .NET Framework have any methods for converting a path (e.g. "C:\whatever.txt"
) into a file URI (e.g. "file:///C:/whatever.txt"
)?
借助的System.Uri 类具有反向(从文件URI来绝对路径),但没有就我能找到转换为文件URI。
The System.Uri class has the reverse (from a file URI to absolute path), but nothing as far as I can find for converting to a file URI.
此外,这是不可以的ASP.NET应用程序。
Also, this is not an ASP.NET application.
推荐答案
在的System.Uri
构造函数来解析完整的文件路径,并把它们变成URI风格的路径的能力。所以,你可以做到以下几点:
The System.Uri
constructor has the ability to parse full file paths and turn them into URI style paths. So you can just do the following:
var uri = new System.Uri("c:\\foo");
var converted = uri.AbsoluteUri;
这篇关于转换文件的文件路径URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!