我有这个函数获取fileData作为字节数组和文件路径。我得到的错误是当它试图在代码bewlo中设置fileInfo时。它说,“给定的物理路径,预计虚拟路径”从物理路径转换到虚拟路径
public override void WriteBinaryStorage(byte[] fileData, string filePath)
{
try
{
// Create directory if not exists.
System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(filePath)); //when it gets to this line the error is caught
if (!fileInfo.Directory.Exists)
{
fileInfo.Directory.Create();
}
// Write the binary content.
System.IO.File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath(filePath), fileData);
}
catch (Exception)
{
throw;
}
}
当调试它,在提供的文件路径为"E:\\WEBS\\webapp\\default\\images\\mains\\myimage.jpg"
。和错误消息是
'E:/WEBS/webapp/default/images/mains/myimage.jpg' is a physical path, but a virtual path was expected.
而且,它是什么触发此发生的是下面的调用
properties.ResizeImage(imageName, Configurations.ConfigSettings.MaxImageSize, Server.MapPath(Configurations.EnvironmentConfig.LargeImagePath));
我可以知道为什么投了反对票我是新来的C#。请体谅 – user710502
您了解'MapPath'的作用以及您的代码正在尝试做什么? – SLaks
这是现有的代码,我没有写它..我的理解是,MapPath是一个函数,将采取虚拟路径并将其转换到服务器路径?,但我又是新的,我可能忽略了显而易见的。没有粗鲁,我来到这个论坛问一个我不确定的问题。没有必要投票..我想这是什么论坛是没有?其他方面,我只是想通过个人资料进行个人资料分析,并且仅仅因为它的干扰而做了一堆否定的投票。 – user710502