예제 #1
0
        public static void AddWaterMark(string originalImagePath)
        {
            string filename  = "";
            string extension = Path.GetExtension(originalImagePath);

            filename = originalImagePath.Replace(extension, "WaterMark" + extension);
            WaterMarkText  waterMarkTextInfo  = SiteConfig.WaterMarkConfig.WaterMarkTextInfo;
            WaterMarkImage waterMarkImageInfo = SiteConfig.WaterMarkConfig.WaterMarkImageInfo;
            int            waterMarkType      = SiteConfig.WaterMarkConfig.WaterMarkType;
            string         str4 = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.UploadDir);
            string         str5 = VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Server.MapPath("~/"));

            originalImagePath = str5 + str4 + originalImagePath;
            filename          = str5 + str4 + filename;
            Image image = null;

            try
            {
                image = Image.FromFile(originalImagePath);
            }
            catch (FileNotFoundException)
            {
                CustomException.ThrowBllException("添加水印的源图片未找到。");
            }
            Bitmap   bitmap  = new Bitmap(image.Width, image.Height, PixelFormat.Format24bppRgb);
            Graphics picture = Graphics.FromImage(bitmap);

            picture.Clear(Color.Green);
            picture.SmoothingMode     = SmoothingMode.HighQuality;
            picture.InterpolationMode = InterpolationMode.High;
            picture.DrawImage(image, 0, 0, image.Width, image.Height);
            switch (waterMarkType)
            {
            case 0:
                AddWatermarkText(picture, waterMarkTextInfo, image.Width, image.Height);
                break;

            case 1:
                AddWatermarkImage(picture, waterMarkImageInfo, image.Width, image.Height);
                break;
            }
            try
            {
                bitmap.Save(filename, ImageFormat.Jpeg);
            }
            catch (ArgumentNullException)
            {
                CustomException.ThrowBllException("该图像的保存路径未找到。");
            }
            finally
            {
                bitmap.Dispose();
                image.Dispose();
                picture.Dispose();
            }
            FileSystemObject.Delete(originalImagePath, FsoMethod.File);
            string newFile = filename.Replace("WaterMark", "");

            FileSystemObject.Move(filename, newFile, FsoMethod.File);
        }
 protected void EBtnModifyName_Click(object sender, EventArgs e)
 {
     if (this.Page.IsValid)
     {
         string str     = this.currentDirectory + @"\";
         string oldFile = str + this.HdnName.Value;
         try
         {
             if (this.HdnType.Value == "1")
             {
                 string file = str + this.TxtDirName.Text;
                 if (oldFile == file)
                 {
                     AdminPage.WriteErrMsg("重命名目录名不能和原来目录名一样!", this.m_UrlReferrer);
                 }
                 if (!FileSystemObject.IsExist(file, FsoMethod.Folder))
                 {
                     FileSystemObject.Move(oldFile, file, FsoMethod.Folder);
                     base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                     AdminPage.WriteSuccessMsg("重命名目录成功", this.m_UrlReferrer);
                 }
                 else
                 {
                     AdminPage.WriteErrMsg("<li>重命目标目录名已经存在。</li>", this.m_UrlReferrer);
                 }
             }
             else
             {
                 string str4 = str + this.TxtFileName.Text;
                 if (oldFile == str4)
                 {
                     AdminPage.WriteErrMsg("重命名文件名不能和原来文件名一样!", this.m_UrlReferrer);
                 }
                 if (!FileSystemObject.IsExist(str4, FsoMethod.File))
                 {
                     FileSystemObject.Move(oldFile, str4, FsoMethod.File);
                     AdminPage.WriteSuccessMsg("重命名文件成功", this.m_UrlReferrer);
                 }
                 else
                 {
                     AdminPage.WriteErrMsg("<li>重命目标文件名已经存在。</li>", this.m_UrlReferrer);
                 }
             }
         }
         catch (FileNotFoundException)
         {
             AdminPage.WriteErrMsg("文件未找到", this.m_UrlReferrer);
         }
         catch (UnauthorizedAccessException)
         {
             AdminPage.WriteErrMsg("<li>重命名文件夹或文件失败!检查您的服务器是否给风格文件夹写入权限。</li>", this.m_UrlReferrer);
         }
     }
 }
            internal bool RenameElement(FileSystemObject item, string path, Func <string, bool> ShouldReplaceFile)
            {
                string oldName = item.FullName;

                if (item.Move(path, () => ShouldReplaceFile(path)))
                {
                    //This is done implicitly by RemoveProjectChild and InsertChildAlphabetically
                    m_contents.Remove(oldName);
                    m_contents.Add(path);
                    return(true);
                }
                return(false);
            }
 protected void BtnMove_Click(object sender, EventArgs e)
 {
     if (this.EgvFiles.SelectList.Length == 0)
     {
         AdminPage.WriteErrMsg("未选中文件或文件夹", this.m_UrlReferrer);
     }
     else
     {
         string[] strArray = this.EgvFiles.SelectList.ToString().Split(new char[] { ',' });
         string   path     = base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir;
         if (string.IsNullOrEmpty(this.DrpMove.SelectedValue))
         {
             AdminPage.WriteErrMsg("<li>请选择目标文件夹</li>", this.m_UrlReferrer);
         }
         try
         {
             DirectoryInfo info = new DirectoryInfo(path);
             if (info.Exists)
             {
                 foreach (string str2 in strArray)
                 {
                     if (!string.IsNullOrEmpty(str2))
                     {
                         string        str3  = info.FullName + this.DrpMove.SelectedValue + str2;
                         DirectoryInfo info2 = new DirectoryInfo(this.currentDirectory + str2 + "/");
                         DirectoryInfo info3 = new DirectoryInfo(info.FullName + this.DrpMove.SelectedValue);
                         DirectoryInfo info4 = new DirectoryInfo(str3);
                         if (info2.Exists)
                         {
                             if (info3.FullName == info2.FullName)
                             {
                                 AdminPage.WriteErrMsg("<li>不能移动到自己目录下</li>", this.m_UrlReferrer);
                             }
                             if (info2.FullName == info4.FullName)
                             {
                                 AdminPage.WriteErrMsg("<li>不能移动到相同目录下</li>", this.m_UrlReferrer);
                             }
                             if (info4.Exists)
                             {
                                 AdminPage.WriteErrMsg("<li>目标目录已经存在</li>", this.m_UrlReferrer);
                             }
                             FileSystemObject.Move(info2.FullName, str3, FsoMethod.Folder);
                             Template.UpdateFileName(BasePage.RequestString("Dir") + "/" + str2, this.DrpMove.SelectedValue + str2);
                         }
                         FileInfo info5 = new FileInfo(this.currentDirectory + str2);
                         FileInfo info6 = new FileInfo(str3);
                         if (info5.Exists)
                         {
                             if (info5.FullName == info6.FullName)
                             {
                                 AdminPage.WriteErrMsg("<li>目标路径与源路径相同</li>", this.m_UrlReferrer);
                             }
                             if (info6.Exists)
                             {
                                 AdminPage.WriteErrMsg("<li>目标文件已经存在</li>", this.m_UrlReferrer);
                             }
                             FileSystemObject.Move(info5.FullName, str3, FsoMethod.File);
                             Template.UpdateFileName(BasePage.RequestString("Dir") + "/" + str2, this.DrpMove.SelectedValue + str2);
                         }
                     }
                 }
                 base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                 AdminPage.WriteSuccessMsg("移动成功", this.m_UrlReferrer);
             }
         }
         catch (FileNotFoundException)
         {
             AdminPage.WriteErrMsg("<li>文件未找到</li>", this.m_UrlReferrer);
         }
         catch (UnauthorizedAccessException)
         {
             AdminPage.WriteErrMsg("<li>移动文件夹或文件时失败!检查您的服务器是否给模板文件夹写入权限。</li>", this.m_UrlReferrer);
         }
     }
 }
 protected void EBtnModifyName_Click(object sender, EventArgs e)
 {
     if (this.Page.IsValid)
     {
         string str            = this.currentDirectory + @"\";
         string oldFile        = str + this.HdnName.Value;
         string successMessage = "";
         try
         {
             if (this.HdnType.Value == "1")
             {
                 string file = str + this.TxtDirName.Text;
                 if (oldFile == file)
                 {
                     AdminPage.WriteErrMsg("重命名目录名不能和原来目录名一样!", this.m_UrlReferrer);
                 }
                 if (!FileSystemObject.IsExist(file, FsoMethod.Folder))
                 {
                     FileSystemObject.Move(oldFile, file, FsoMethod.Folder);
                     base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                     successMessage = "重命名目录成功!";
                     if (this.ChkUpdateFolderContactinformation.Checked)
                     {
                         DirectoryInfo info  = new DirectoryInfo(base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir);
                         DirectoryInfo info2 = new DirectoryInfo(oldFile);
                         DirectoryInfo info3 = new DirectoryInfo(file);
                         oldFile = info2.FullName.Replace(info.FullName, "");
                         file    = info3.FullName.Replace(info.FullName, "");
                         oldFile = oldFile.Replace(@"\", "/");
                         Template.ReplaceTemplateDir(oldFile + "/", file.Replace(@"\", "/") + "/");
                         successMessage = successMessage + "相关联该目录的模板引用已改变!";
                     }
                 }
                 else
                 {
                     AdminPage.WriteErrMsg("<li>重命目标目录名已经存在。</li>", this.m_UrlReferrer);
                 }
             }
             else
             {
                 string str6 = str + this.TxtFileName.Text;
                 if (oldFile == str6)
                 {
                     AdminPage.WriteErrMsg("重命名文件名不能和原来文件名一样!", this.m_UrlReferrer);
                 }
                 if (!FileSystemObject.IsExist(str6, FsoMethod.File))
                 {
                     FileSystemObject.Move(oldFile, str6, FsoMethod.File);
                     successMessage = "重命名文件成功!";
                     if (this.ChkUpdateFileContactinformation.Checked)
                     {
                         DirectoryInfo info4 = new DirectoryInfo(base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir);
                         FileInfo      info5 = new FileInfo(oldFile);
                         FileInfo      info6 = new FileInfo(str6);
                         oldFile = info5.FullName.Replace(info4.FullName, "");
                         str6    = info6.FullName.Replace(info4.FullName, "");
                         oldFile = oldFile.Replace(@"\", "/");
                         str6    = str6.Replace(@"\", "/");
                         Template.UpdateFileName(oldFile, str6);
                         successMessage = successMessage + "相关联该文件的模板引用已改变!";
                     }
                 }
                 else
                 {
                     AdminPage.WriteErrMsg("<li>重命目标文件名已经存在。</li>", this.m_UrlReferrer);
                 }
             }
             AdminPage.WriteSuccessMsg(successMessage, this.m_UrlReferrer);
         }
         catch (FileNotFoundException)
         {
             AdminPage.WriteErrMsg("文件未找到", this.m_UrlReferrer);
         }
         catch (UnauthorizedAccessException)
         {
             AdminPage.WriteErrMsg("<li>重命名文件夹或文件失败!检查您的服务器是否给模板文件夹写入权限。</li>", this.m_UrlReferrer);
         }
     }
 }