上传图片时出现错误

赵军洁 赵军洁 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public bool SaveFile(byte[] binData,string fileName){
bool success=false;

string savePath=System.Configuration.ConfigurationSettings.AppSettings["UploadDirectory"];
if(savePath==null) savePath="Photo";
savePath=Server.MapPath(savePath);
if(!savePath.EndsWith("\\")) savePath += "\\";

if(!Directory.Exists(savePath)){
throw new Exception("服务器端没有找到有效的保存路径!");
}

FileStream fileStream=null;
try{
fileStream=new FileStream(savePath + fileName,FileMode.Create,FileAccess.Write);
//write the file
fileStream.Write(binData,0,binData.Length);
fileStream.Flush();//clear the buffer,write the data to the hard disk
success=true;
}catch(Exception ex){
throw new Exception(ex.Message);
}finally{
fileStream.Close();
}
return success;

}


这个是我写的保存图片的代码,但是上传的时候说找不到此路径,为什么啊?
...全文
评论 5
收藏 已收藏
分享
返回顶部
赵军洁
.NET社区 62,274 成员 668,968 内容