Server.MapPath 为什么在根目录下生成不了文件?
id = Request.QueryString["id"].GetInt();
BLL.Links lk=new BLL.Links();
Model.Links l;
if (id > 0)
{
l = lk.GetModel(id);
}
else
{
l = new Model.Links();
}
ProcessImage p = new ProcessImage();
string LogoUrl = "";
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
l.Name = txtName.Text;
l.Paixu = txtPaixu.Text.GetInt();
l.Url = txtUrl.Text;
l.IsXianshi = rdlxianshi.SelectedValue.GetInt();
l.Addtime = dataName.GetDateTime();
if ("add".Equals(Request.QueryString["id"].GetString()))
{
if (FileUpload1.HasFile)
{
HttpPostedFile postfile = FileUpload1.PostedFile;
string ext = Path.GetExtension(postfile.FileName);
if (ext == ".bmp" || ext == ".jpg" || ext == ".gif" || ext == ".JPG" || ext == ".BMP" || ext == ".GIF")
{
string path = "~/upload/links/" + dataName + ext; int res = 2;
//0:创建缩略图失败,1:传入的文件格式错误,2:创建成功
try
{
res = p.CreateThumbnail(postfile, Server.MapPath(path), 100, 100); }
catch { }
LogoUrl = "~/upload/links/" + dataName + ext;
l.LogoUrl = LogoUrl;
lk.Add(l);
Alert("添加成功", "List.aspx");
}
else
{
Alert("图片格式不对");
}
}
else
{
l.LogoUrl = value;
lk.Update(l);
Alert("修改成功", "List.aspx");
}
}
------解决方案--------------------
保证要上传的文件夹开了写入权限.
------解决方案--------------------
1.检查上传的文件夹是否开启了写入权限
2.检查路径是否正确。