URL格式不支持 [英] URL Formats are not supported

查看:1107
本文介绍了URL格式不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读文件,File.OpenRead方法,我给这条道路。

 的http://本地主机:10001 / MYFILES /文件夹/ abc.png

我已经试过这样做,但没有运气

 的http://本地主机:10001 // // MYFILES abc.png

但其捐赠


  

URL格式不被支持


当我把我的驱动器这样的物理路径,它工作正常
D:\\ MyFolder文件\\ MyProject的\\ MYFILES \\文件夹\\ abc.png

我怎么可以给文件路径HTTP路径?

这是我的code

 公共的FileStream的GetFile(字符串文件名)
{
    的FileStream文件= File.OpenRead(文件名);
    返回文件;
}


解决方案

您既可以使用Web客户端在其他的答案提出或获取类似这样的相对路径:

  VAR URL =HTTP://本地主机:10001 / MYFILES /文件夹/ abc.pngVAR URI =新的URI(URL);
VAR路径= Path.GetFileName(uri.AbsolutePath);var文件=的GetFile(路径);
// ...

在一般你应该摆脱绝对URL。

I am reading File with File.OpenRead method, I am giving this path

   http://localhost:10001/MyFiles/folder/abc.png

I have tried this as well but no luck

http://localhost:10001//MyFiles//abc.png

but its giving

URL Formats are not supported

When I give physical path of my Drive like this,It works fine d:\MyFolder\MyProject\MyFiles\folder\abc.png

How can I give file path to an Http path?

this is my code

public FileStream GetFile(string filename)
{
    FileStream file = File.OpenRead(filename);
    return file;
}

解决方案

You could either use a WebClient as suggested in other answers or fetch the relative path like this:

var url = "http://localhost:10001/MyFiles/folder/abc.png";

var uri = new Uri(url);
var path = Path.GetFileName(uri.AbsolutePath);

var file = GetFile(path);
// ...

In general you should get rid of the absolute URLs.

这篇关于URL格式不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆