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

1 回答 1

0

Your application need writing permission on the folder where you're going to save the pictures. Depending wich version of IIS you're running, permissions most be granted to ASPNET user (IIS 6) or the account used for application pool (IIS 7).

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

Best regards.

于 2012-05-11T06:57:27.297 回答