Converting a URI path to a relative file system path in .NET

后端 未结 4 783
故里飘歌
故里飘歌 2020-12-30 18:36

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

4条回答
  •  长发绾君心
    2020-12-30 19:13

    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);
    }
    

提交回复
热议问题