上传图片无法进入系统

时间:2012-05-11 06:49:09

标签: c# web-services

我创建了一个表单,将图片上传到我的系统,但图片上传失败。

我尝试在我的系统中使用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;
    }

1 个答案:

答案 0 :(得分: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

最好的问候。