[英]How Can I Use File.Create Web Path as Parameter at .Net Core
Version.NetCore 2.1 在 IIS 上有一个共享路径,例如 h ttps://foo.com/bar" 这个 bar 文件夹在 IIS 我的 web 站点上
http-s://mysite.com/bar/request 返回状态码 200
如果 targetFilePath 为“z:\myfiles\cookieRecipe.txt”,则此代码将成功。
但是如果 targetFilePath 是"http-s://mysite.com/bar/cookieRecipe.txt"这会抛出一个异常,比如 "System.IO.IOException","HResult":-2147024773,"Message":"The filename, directory名称或卷 label 语法不正确Z:\Publish\MyWeb.Web\http-s:\mysite.com\bar"为什么此代码将 Z:\Publish\MyWeb.Web 添加到我的路径? 我该如何解决这个问题?
using (var targetStream = File.Create(targetFilePath))
{
await item.CopyToAsync(targetStream);
}
该文档解释了 file.open(path) 仅支持相对或绝对路径。相对路径信息被解释为相对于当前工作目录
https://docs.microsoft.com/en-us/dotnet/api/system.io.file.create?view=netcore-3.1
如果您想从远程读取某些内容,请改用 webclient。
WebClient client = new WebClient();
Stream stream = client.OpenRead("https://mysite/a");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.