Asp.net Webforms - 如何使用二进制读取文件 Reader

Asp.net Webforms - How to Read a file Using Binary Reader

我有一个文件,我按如下方式调整图像大小后将其上传到临时文件夹:

/uploads/temp/myfile.jpg

如果我只有上面指示的文件路径,我如何将此文件读入二进制文件 reader,即在下面的示例中我得到错误:

Error in saving fileSystem.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\uploads\temp\myfile.jpg'

 var fs = new FileStream('/uploads/temp/myfile.jpg', FileMode.Open);
 using (var reader = new BinaryReader(fs))
 {
      image.ImageContent = reader.ReadBytes((int)fs.Length);
 }

通过执行以下操作设法修复:

 var fs = new FileStream(HostingEnvironment.MapPath("~/") + "/uploads/temp/myfile.jpg", FileMode.Open);