大家看看这段代码有没有什么问题?图片每次上传就是失败的~~ 也没有出现任何错误提示~~希望大家可以帮帮忙
   protected void upload1Button_Click(object sender, EventArgs e)
    {
        // proceed with uploading only if the user selected a file
        if (image1FileUpload.HasFile)
        {
            try
            {
                string fileName = image1FileUpload.FileName;
                string location = Server.MapPath("./ProductImages/") + fileName;
                // save image to server
                image1FileUpload.SaveAs(location);
                // update database with new product details
                ProductDetails pd = CatalogAccess.GetProductDetails(currentProductId);
                CatalogAccess.UpdateProduct(currentProductId, pd.Name, pd.Description, pd.Price.ToString(), fileName, pd.Image2FileName, pd.OnDepartmentPromotion.ToString(), pd.OnCatalogPromotion.ToString());
                // reload the page 
                Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" +"?DepartmentID=" + currentDepartmentId + "&CategoryID=" + currentCategoryId +"&ProductID=" + currentProductId);
            }
            catch
            {
                statusLabel.Text = "上传图片失败";
            }
        }
    }

解决方案 »

  1.   

       ProductDetails pd = CatalogAccess.GetProductDetails(currentProductId); 
                    CatalogAccess.UpdateProduct(currentProductId, pd.Name, pd.Description, pd.Price.ToString(), fileName, pd.Image2FileName, pd.OnDepartmentPromotion.ToString(), pd.OnCatalogPromotion.ToString()); 
                    // reload the page 
                    Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" +"?DepartmentID=" + currentDepartmentId + "&CategoryID=" + currentCategoryId +"&ProductID=" + currentProductId); 
    这两句里有问题,或者是服务器目录没有写权限。
      

  2.   

    去掉错误捕捉后,出现了下面的错误提示用户代码未处理 System.UnauthorizedAccessException
      Message="对路径“c:\\inetpub\\wwwroot\\BalloonShop\\ProductImages\\222.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)
           在 ProductDetailsAdmin.upload1Button_Click(Object sender, EventArgs e) 位置 c:\Inetpub\wwwroot\BalloonShop\UserControls\ProductDetailsAdmin.ascx.cs:行号 182
           在 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)
      

  3.   

    就是写入权限的问题。。默认情况下WEB程序不能改写磁盘,(好像是默认可以读)
    要么你给你这个站点的目录分配 读写权限给 ASPNET账号
    或者给你的这个站点绑定一个你自己建立的账号,让这个账号有权利读写这个目录。
      

  4.   

    权限。。   到IIS里给这个站点分配一个 WINDOWS账号  并给这个账号指定好磁盘、组件权限。最简单的办法 是把你的 站点磁盘目录指定 everyone的完全权限,  不过这样太不安全