日期:2014-05-18  浏览次数:20404 次

上传到服务器的错误
asp.net网站 在本地测试的时候 , 上传没有问题 不会出现路径找不到的错误
而把代码上传到服务器之后 就出现找不到要上传的文件的路径 “找不到..../桌面/。。。。jpg图片的路径”

代码如下: 
  public int UpdateHead(string filename, FileUpload fu,string sessionname)
  {
  int mes_key = 0;
  string fileleixing;
  fileleixing = System.IO.Path.GetExtension(filename).ToString();
  if (fu.PostedFile.ContentLength > 294800)
  {
  mes_key = 2;


  }
   
  else if (DataOperate.IsAllowedExtension(fu))
  {
   
  Random rmd = new Random();
  string filepath = null;
  filepath = System.DateTime.Now.ToString() + rmd.Next(1, 65535);
  filepath = filepath.Replace(":", "").Replace(" ", "").Replace("-", "") + fileleixing; //生成文件名 
  fu.SaveAs(System.Web.HttpContext.Current.Server.MapPath("headimage/" + filepath)); //上传文件到指定的目录,上传文件成功


  if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("headimage/") + filepath))
  {
  string uploadurl =filepath; //获取新头像的web路径
  UserDataClassesDataContext d = new UserDataClassesDataContext();
  ManagerOr mor = d.ManagerOrs.Single(uor => uor.manname == sessionname.ToString());
  if (mor.manhead != "morenmanger.jpg") //用于判断是否是系统的默认头像 如果不是则删除该图片
  {
  string delurl = System.Web.HttpContext.Current.Server.MapPath("headimage/" + mor.manhead.ToString());
  System.IO.FileInfo file = new System.IO.FileInfo(delurl);
  if (file.Exists)
  {

  file.Delete(); //先删除原来的头像文件
  }
  }
  mor.manhead = uploadurl; //再将新的文件url插入数据库
  try
  {
  d.SubmitChanges();
  mes_key = 1;
  }
  catch (Exception ex)
  {
  mes_key = -1;
  }
  }
  else
  {
  mes_key = -1;
  }
  }else
  {
  //提示用户只能上传jpg和gif格式
  mes_key = 0;
  }
  return mes_key;
  }

------解决方案--------------------
路径问题,你那路径是啥玩意
------解决方案--------------------
明显路径问题 啊