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

asp.net 图片上传路径问题,急,在线等待!谢谢!
图片上传代码如下:
  string fileContentType = FileUpload1.PostedFile.ContentType;
  if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/jpg")
  {

  string name = FileUpload1.PostedFile.FileName; // 客户端文件路径
  string file = name.Substring(name.LastIndexOf("\\") + 1);
  string fileName = file; // 文件名称
  string fileName_s = "s_" + file; // 缩略图文件名称
  string webFilePath = Server.MapPath("file/" + fileName); // 服务器端文件路径
  string webFilePath_s = Server.MapPath("file/" + fileName_s);   // 服务器端缩略图路径
  if (!File.Exists(webFilePath))
  {

  // 使用 SaveAs 方法保存文件
  FileUpload1.PostedFile.SaveAs(webFilePath_s);
  FileUpload1.SaveAs(webFilePath);
  this.Image1.ImageUrl = "file/" + file;

  }
  }
我把图片传到了我的工程下的file文件夹里,在ACCESS数据库中存放图片路径,但是存放的路径是
F:\MyWork\新闻管理系统\NewsNet\file\s_2.jpg,我想要得到的路径是file\s_2.jpg
怎么办啊?帮帮忙,因为,只要一离开我这台机子,到别的机子上就无法显示出来图片,急啊!

------解决方案--------------------
那就真接保存"file/" + file到数据库,不要存物理地址.
lz没有把存放数据库部分的代码贴出来,而贴了段无关的代码.