将文件路径转换为文件 URI? [英] Convert file path to a file URI?
本文介绍了将文件路径转换为文件 URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
.NET Framework 是否有任何方法可以将路径(例如 "C:whatever.txt"
) 转换为文件 URI(例如 "file:///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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文