我正在使用 File.OpenRead 方法读取文件,我给出这个路径
http://localhost:10001/MyFiles/folder/abc.png
我也尝试过这个,但没有运气
http://localhost:10001//MyFiles//abc.png
但它的给予
不支持 URL 格式
当我像这样给出我的驱动器的物理路径时,它工作得很好
d:\MyFolder\MyProject\MyFiles\folder\abc.png
如何将文件路径指定为 Http 路径?
这是我的代码
public FileStream GetFile(string filename)
{
FileStream file = File.OpenRead(filename);
return file;
}
看一下WebClient
(MSDN 文档),它有许多从网络下载数据的实用方法。
如果您希望资源作为Stream
, try:
using(WebClient webClient = new WebClient())
{
using(Stream stream = webClient.OpenRead(uriString))
{
using( StreamReader sr = new StreamReader(stream) )
{
Console.WriteLine(sr.ReadToEnd());
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)