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

图片上传控件使用出现的问题!!!!!!请前辈指导
本人想使用Fileupload控件对图片进行浏览和上传,另外设置了一个按钮,用来确定上传
保存在虚拟空间内
代码如下--------按钮的单击响应事件:
protected void Button3_Click(object sender, EventArgs e)
  {
  string name = FileUpload1.FileName; //获取已上传的文件的名字
  string size = FileUpload1.PostedFile.ContentLength.ToString();//获取已上传文件的大小
  string type = FileUpload1.PostedFile.ContentType;//获取上传文件的类型
  string type2 = name.Substring(name.LastIndexOf(".") + 1); 
  string ipath = Server.MapPath("upimg") + "\\" + name; //这里的upimg是存储图片内容的服务器地址路径
  string fpath = Server.MapPath("upfile") + "\\" + name;//这里的upfile是存储文档内容的服务器地址路径
  string wpath = "upimg\\" + name;//这里是已经写入到数据库里的虚拟路径
  //判断文件格式
  if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png")
  {
  FileUpload1.SaveAs(ipath);
  ImageButton1.ImageUrl = wpath;
}
  else
  {
  ImageButton1.Visible = false;
  FileUpload1.SaveAs(fpath); }



错误提示--------------未能找到路径“F:\\peter-学习\\网站--C#\\asp01\\upimg\\IMG_1183.jpg”的一部分

///////////////显示的错误我复制过来了//////////////////////////////////////////////////////////////////////////////////////////

用户代码未处理 System.IO.DirectoryNotFoundException
  Message="未能找到路径“F:\\peter-学习\\网站--C#\\asp01\\upimg\\IMG_1183.jpg”的一部分。"
  Source="mscorlib"
  StackTrace:
  在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  在 System.IO.FileStream..ctor(String path, FileMode mode)
  在 System.Web.HttpPostedFile.SaveAs(String filename)
  在 System.Web.UI.WebControls.FileUpload.SaveAs(String filename)
  在 welco.Button3_Click(Object sender, EventArgs e) 位置 f:\peter-学习\网站--C#\asp01\welco.aspx.cs:行号 122
  在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
  在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
  在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
  在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
  在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)







看哪位前辈可以指点一下啊


------解决方案--------------------
你这个upimg应该是服务器上的一个文件夹咯?那如果你要把图片放里面肯定是要手动新建一个的