if (this.userPicture.PostedFile.FileName == "")
{
Response.Write("<script>alert('文件名不能为空!');</script>");
this.userPicture.Focus();
}
else
{
string fullFileName = this.userPicture.PostedFile.FileName;
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); string UserDirectory = "GenreImg";//所要创建文件夹的名字,实际运用中可为用户注册ID
string UserPath = Server.MapPath("Images").ToString() + "\\" + UserDirectory;
if (!Directory.Exists(UserPath)) //如果文件夹不存在则创建
{
Directory.CreateDirectory(UserPath);
}
string sUser_ProductsImageUrl = "../images/" + UserDirectory + "\\" + fileName;//得到服务端图片的虚拟路径
this.userPicture.PostedFile.SaveAs(Server.MapPath(sUser_ProductsImageUrl));//用保存的方法将图片上载(此处出错)错误是:未能映射路径“/images/GenreImg/accept.gif”。
请高手指教!!!
{
Response.Write("<script>alert('文件名不能为空!');</script>");
this.userPicture.Focus();
}
else
{
string fullFileName = this.userPicture.PostedFile.FileName;
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); string UserDirectory = "GenreImg";//所要创建文件夹的名字,实际运用中可为用户注册ID
string UserPath = Server.MapPath("Images").ToString() + "\\" + UserDirectory;
if (!Directory.Exists(UserPath)) //如果文件夹不存在则创建
{
Directory.CreateDirectory(UserPath);
}
string sUser_ProductsImageUrl = "../images/" + UserDirectory + "\\" + fileName;//得到服务端图片的虚拟路径
this.userPicture.PostedFile.SaveAs(Server.MapPath(sUser_ProductsImageUrl));//用保存的方法将图片上载(此处出错)错误是:未能映射路径“/images/GenreImg/accept.gif”。
请高手指教!!!
//得到服务端图片的虚拟路径
string sUser_ProductsImageUrl =Server.MapPath("..")+"\\images\\" + UserDirectory + "\\" + fileName;//用保存的方法将图片上载(此处出错)
this.userPicture.PostedFile.SaveAs(sUser_ProductsImageUrl);
--------------------------------------------------------------
程序,犹如人生。