2012-05-11 13 views
0

画像を自分のシステムにアップロードするためのフォームを作成しましたが、画像のアップロードに失敗しました。アップロード画像がシステムに失敗する

自分のWebサービスが私のシステムに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

こんにちはオスカー、どのように許可を取得するには?そのステップは? 返信用 –

+0

私が言うように、実行しているIISのバージョンによって異なります。あなたはどちらを持っていますか? – Oscar

+0

私は間違いない〜私のIISバージョンはIIS 7です –

関連する問題