转换一个URI路径在.NET中的相对文件系统路径 [英] Converting a URI path to a relative file system path in .NET
本文介绍了转换一个URI路径在.NET中的相对文件系统路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何转换成一个绝对或相对的URI路径(如 /foo/bar.txt
)到(segmentwise)对应的相对文件系统路径(例如:<$ C C $> FOO \跳回到bar.txt )的.NET?
How do I convert an absolute or relative URI path (e.g. /foo/bar.txt
) to a (segmentwise) corresponding relative file system path (e.g. foo\bar.txt
) in .NET?
我的程序不是一个ASP.NET应用程序。
My program is not an ASP.NET application.
推荐答案
你已经尝试过使用Server.Mappath
?
或 Uri.LocalPath
属性?喜欢的东西如下:
Have you already tried Server.MapPath
?
or Uri.LocalPath
property? Something like following :
string uriString = "file://server/filename.ext";
// Lesson learnt - always check for a valid URI
if(Uri.IsWellFormedUriString(uriString))
{
Uri uri = new Uri(uriString);
Console.WriteLine(uri.LocalPath);
}
这篇关于转换一个URI路径在.NET中的相对文件系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文