2012-05-11 63 views
0

我創建了一張表單上傳圖片到我的系統,但圖片上傳失敗。上傳圖片失敗系統

我試着在我的系統中使用getCurrentTime()連接我的網絡服務,並且連接成功。

我的朋友告訴我應該是服務器問題,但我的朋友和我真的不知道如何檢查我們的服務器是否已成功連接到我們的系統。

任何人都可以幫助我解決這個問題嗎?

提前致謝。

我的代碼

protected void btnSave_Click(object sender, EventArgs e) 
    { 
     string fileName = string.Empty; 
     if (File2.PostedFile != null) 
     { 
      fileName = System.IO.Path.GetFileName(File2.PostedFile.FileName); 
     } 
     if (fileName != string.Empty) 
     { 
      if (!this.CheckFileFormat(fileName)) 
      { 
       WindowJS.WindowAlert("Image format is incorrect !"); 
       return; 
      } 
      string server = ImageURL; 
      string unique = Guid.NewGuid().ToString(); 
      string filePath = server.TrimEnd('\\').TrimEnd('/') + ImageURLRelative + unique + "." + fileName.Split('.')[1].ToString(); 
      // string LocalfilePath = Server.MapPath("..") + unique + "." + fileName.Split('.')[1].ToString(); 
      string uploadFileName = unique + "." + fileName.Split('.')[1].ToString(); 
      try 
      { 
       HttpPostedFile mFile = File2.PostedFile; 

       int fileSize = mFile.ContentLength; 
       int done = 0; 

       byte[] mFileByte = new Byte[fileSize]; 
       mFile.InputStream.Read(mFileByte, 0, fileSize); 

       string WebServiceUrl = string.Empty; 


       try 
       {      
        Rewards.high5.RedemptionUpload high5UploadService = new Rewards.high5.RedemptionUpload(); 

        if (Brand == "high5") 
        { 
         done = high5UploadService.UploadImage(uploadFileName, mFileByte); 

         if (done == 1) 
         { 

         } 
         else 
         { 
          WindowJS.WindowAlert("Error: Upload image fail."); 
          return; 
         } 
        } 
        //else if (Brand == "TLC") 
        //{ 
        // done = TLCUploadService.UploadImage(uploadFileName, mFileByte); 
        //} 


       } 
       catch (Exception ex) 
       { 
        WindowJS.WindowAlert("Error: Upload image fail."); 
        return; 
       } 
      } 
      catch (Exception ex) 
      { WindowJS.WindowAlert(ex.Message.ToString()); } 
      try 
      { 
       File2.PostedFile.SaveAs(filePath); 
       ImgUrl.ImageUrl = ImageURLRelative + unique + "." + fileName.Split('.')[1].ToString(); 
      } 
      catch (Exception ex) 
      { 
       WindowJS.WindowAlert(ex.Message.ToString()); 
      } 
      ViewState["IMG"] = ImageURLRelative + unique + "." + fileName.Split('.')[1].ToString(); 
     } 
     if (txtName.Text.Trim() == string.Empty) 
     { 
      WindowJS.WindowAlert("Please input the Name !"); 
      return; 
     } 
     try 
     { 
      Convert.ToDecimal(txtPoint.Text.Trim()); 
     } 
     catch 
     { 
      WindowJS.WindowAlert("Please input the Points correctly"); 
      return; 
     } 
     if (ViewState["Type"].ToString() == "E") 
     { 
      int rows = EditRedemption(); 
      if (rows == 0) 
      { 
       WindowJS.WindowAlert("Failed to modify"); 
      } 
      else 
      { 
       WindowJS.WindowAlert("Modified successfully"); 
       LoadInfo("V"); 

      } 


      return; 
     } 
     else if (ViewState["Type"].ToString() == "A") 
     { 
      AB5VIP.BLL.Redemption red = new AB5VIP.BLL.Redemption(); 
      if (red.Exists_RedName(txtName.Text.Trim())) 
      { 
       WindowJS.WindowAlert("This Redemption already existed !"); 
       return; 
      } 
      int rows = AddRedemption(); 
      WindowJS.WindowAlert(rows == 0 ? "Failed to save" : "save successfully"); 
     } 
     else if (ViewState["Type"].ToString() == "V") 
     { 
      AB5VIP.BLL.Redemption redlang = new AB5VIP.BLL.Redemption(); 

      int rows = redlang.UpdateRedemptionLang(Convert.ToInt32(ViewState["ID"].ToString()), ddlLang.SelectedItem.Value, txtName.Text, txtTitle.Text.ToString(), txtDesc.Text, Session["ABP_LoginName"].ToString(), System.DateTime.Now); 
      WindowJS.WindowAlert(rows == 0 ? "Failed to save" : "save successfully"); 
     } 
     lblCode.Text = string.Empty; 
    } 
+4

顯示您的代碼。 –

+0

嗨shree〜我發佈了我的代碼〜 –

+0

thx ravi幫我編輯我的代碼〜我是新來的〜模糊了。 –

回答

0

您的應用程序需要你要去的地方保存圖片的文件夾上寫入權限。根據您正在運行的IIS的最新版本,許多權限授予ASPNET用戶(IIS 6)或用於應用程序池(IIS 7)的帳戶。

http://blogs.msdn.com/b/david.wang/archive/2005/08/20/why-can-i-upload-a-file-without-iis-write-permission.aspx

最好的問候。

+0

嗨奧斯卡,如何獲得許可?步驟是? thx的回覆 –

+0

正如我所說,取決於您的IIS運行的版本。你有哪一個? – Oscar

+0

如果我沒有錯誤〜我的IIS版本是IIS 7 –