AjaxFileUpload将映像保存到本地目录而不是服务器目录

时间:2013-01-31 15:52:12

标签: asp.net-ajax

它会将图像保存到本地目录或根本不保存。 它没有给我任何错误。 据我所知,我的本地驱动器和主机之间没有任何关系。我的所有页面都在主机上,它们工作正常。但是在创建此页面之前,我将bin目录文件(AjaxControlToolkit.dll,Site.dll,site.pdb)从我的localhost导入到Web服务器。

源文件:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderIcerik" runat="server">
  <asp:ToolkitScriptManager runat="server"></asp:ToolkitScriptManager>

  <asp:AjaxFileUpload ID="AjaxFileUploadResimEkle" runat="server"  
    AllowedFileTypes="jpg,jpeg" 
    onuploadcomplete="AjaxFileUploadResimEkle_UploadComplete" />
</asp:Content

&GT;

代码隐藏:

    protected void AjaxFileUploadResimEkle_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
          int PostID = Convert.ToInt32(Request.QueryString["PostID"]);
          var makale = (from p in db.Posts
                        where p.PostID == PostID
                        select new { p.PostID, p.Title }).Single();

          string uzanti = Path.GetExtension(e.FileName);
          if (e.ContentType.Contains("image"))
          {
            if (e.FileSize <41943040)
            {
              Guid benzersiz = Guid.NewGuid();

              string filePath =string.Format("~/images/blog/large_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);

              AjaxFileUploadResimEkle.SaveAs(Server.MapPath(filePath));

              System.Drawing.Image degisecekResim = System.Drawing.Image.FromFile(filePath));

              Bitmap kucukResim = ResimKucult(degisecekResim);
              string kucukResimYolu = string.Format("~/images/blog/medium_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);
              kucukResim.Save(Server.MapPath(kucukResimYolu));

              Resimler resim = new Resimler();

              resim.PostID = PostID;
              resim.FileName = filePath;
              resim.SmallFileName = kucukResimYolu;
              resim.IsActive = true;
              db.Resimlers.AddObject(resim);
              db.SaveChanges();

            }
          }
        }

    Bitmap ResimKucult(System.Drawing.Image resim)
    {
      int x = 225;
      int y = 165;

      Bitmap bmpOrji = new Bitmap(resim);
      if (bmpOrji.Width > bmpOrji.Height)
      {
        y = bmpOrji.Height * x / bmpOrji.Width;
      }
      else if (bmpOrji.Height > bmpOrji.Width)
      {
        x = bmpOrji.Width * y / bmpOrji.Height;
      }

      Bitmap yeniBmp = new Bitmap(bmpOrji, x, y);

      return yeniBmp;
    }

  }

1 个答案:

答案 0 :(得分:0)

问题出在domainhost的文件夹选项中。当我给文件夹写入权限问题解决了。

我不知道我的主机有那种文件夹选项系统,默认情况下所有文件夹都是只读的。

在弄乱像我这样的asp页面之前,最好先检查一下主机。