UpLoad.cs
上传用户:lanchensha
上传日期:2022-02-27
资源大小:7530k
文件大小:39k
- //------------------------------------------------------------------------------
- // 版权声明
- //DotNetTextBox免费版源码版权由小宝.NET及Aspxcn中华网工作室所有!
- //非盈利性个人网站可免费使用本控件,商业及盈利性网站请购买功能更强大的商业版本授
- //权或开发版,如发现任何个人或机构违反本声明,本站将对其追究法律责任!
- //商业授权及开发版购买地址:http://www.aspxcn.com.cn/dotnettextbox/default.htm
- //联系email:webmaster@aspxcn.com.cn
- //------------------------------------------------------------------------------
- using System;
- using System.Collections;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- namespace DotNetTextBox
- {
- #region 自定义控件的上传功能
- /// <summary>
- /// 文件列表的排序处理
- /// </summary>
- public class SortFile : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- FileInfo fa = (FileInfo)a;
- FileInfo fb = (FileInfo)b;
- if (fa.LastWriteTime < fb.LastWriteTime)
- return 1;
- if (fa.LastWriteTime > fb.LastWriteTime)
- return -1;
- return 0;
- }
- }
- /// <summary>
- /// 上传功能页面的类
- /// </summary>
- public partial class UpLoad : System.Web.UI.Page
- {
- /// <summary>
- /// 页面控件的定义
- /// </summary>
- protected string vrPath;
- protected System.Web.UI.WebControls.HiddenField config_type;
- protected System.Web.UI.WebControls.FileUpload FileUpload1;
- protected System.Web.UI.WebControls.Button uploadBtn;
- protected System.Web.UI.WebControls.Button selectAllBtn;
- protected System.Web.UI.WebControls.Button deleteBtn;
- protected System.Web.UI.WebControls.Button editBtn;
- protected System.Web.UI.WebControls.Button canceloading;
- protected System.Web.UI.WebControls.Button remoteupload;
- protected System.Web.UI.WebControls.Button insertTemplate;
- protected System.Web.UI.WebControls.Label space;
- protected System.Web.UI.WebControls.Label useSpace;
- protected System.Web.UI.WebControls.Label path;
- protected System.Web.UI.WebControls.TextBox file_path;
- protected System.Web.UI.WebControls.TextBox remoteurl;
- protected System.Web.UI.WebControls.TextBox inputx;
- protected System.Web.UI.WebControls.TextBox inputy;
- protected System.Web.UI.WebControls.GridView File_List;
- protected System.Web.UI.WebControls.HiddenField config_maxAllUploadSize;
- protected System.Web.UI.WebControls.HiddenField config_smallImages;
- protected System.Web.UI.WebControls.HiddenField config_watermarkImages_path;
- protected System.Web.UI.WebControls.HiddenField config_watermarkImages;
- protected System.Web.UI.WebControls.HiddenField config_watermarkText;
- protected System.Web.UI.WebControls.HiddenField config_watermakOption;
- protected System.Web.UI.WebControls.HiddenField config_watermark;
- protected System.Web.UI.WebControls.HiddenField config_autoname;
- protected System.Web.UI.WebControls.HiddenField config_allowUpload;
- protected System.Web.UI.WebControls.HiddenField config_fileFilters;
- protected System.Web.UI.WebControls.HiddenField config_maxSingleUploadSize;
- protected System.Web.UI.WebControls.HiddenField config_fileListBox;
- protected System.Web.UI.WebControls.HiddenField config_watermarkImagesName;
- protected System.Web.UI.WebControls.HiddenField config_watermarkName;
- protected System.Web.UI.WebControls.HiddenField config_smallImagesName;
- protected System.Web.UI.WebControls.HiddenField config_smallImagesType;
- protected System.Web.UI.WebControls.HiddenField config_smallImagesW;
- protected System.Web.UI.WebControls.HiddenField config_smallImagesH;
- protected System.Web.UI.WebControls.HiddenField templateContent;
- protected System.Web.UI.WebControls.Label maxSingleUploadSize;
- protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
- protected XmlDocument config = new XmlDocument();
- /// <summary>
- /// 页面的初始化
- /// </summary>
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Response.Expires = -1;
- if (Request.Cookies["uploadConfig"] != null)
- {
- config.Load(Server.UrlDecode(Request.Cookies["uploadConfig"].Value.ToLower()));
- }
- else
- {
- config.Load(HttpContext.Current.Request.PhysicalApplicationPath + "/system_dntb/uploadconfig/default.config");
- }
- if (Request.Cookies["languages"] != null)
- {
- ResourceManager.SiteLanguageKey = Request.Cookies["languages"].Value;
- }
- else
- {
- ResourceManager.SiteLanguageKey = HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"].ToLower().Split(',')[0];
- }
- if (config_type.Value == "Images")
- {
- config_fileFilters.Value = config.SelectNodes("//configuration/imagesFilters")[0].InnerText;
- config_watermarkName.Value = config.SelectNodes("//configuration/watermarkName")[0].InnerText;
- config_watermarkImagesName.Value = config.SelectNodes("//configuration/watermarkImagesName")[0].InnerText;
- config_smallImagesName.Value = config.SelectNodes("//configuration/smallImagesName")[0].InnerText;
- config_smallImagesType.Value = config.SelectNodes("//configuration/smallImagesType")[0].InnerText;
- config_smallImagesW.Value = config.SelectNodes("//configuration/smallImagesW")[0].InnerText;
- config_smallImagesH.Value = config.SelectNodes("//configuration/smallImagesH")[0].InnerText;
- config_smallImages.Value = config.SelectNodes("//configuration/smallImages")[0].InnerText.Trim().ToLower();
- config_watermark.Value = config.SelectNodes("//configuration/watermark")[0].InnerText.Trim().ToLower();
- config_watermarkImages.Value = config.SelectNodes("//configuration/watermarkImages")[0].InnerText.Trim().ToLower();
- config_watermarkImages_path.Value = config.SelectNodes("//configuration/watermarkImages_path")[0].InnerText.Trim();
- config_watermarkText.Value = config.SelectNodes("//configuration/watermarkText")[0].InnerText.Trim();
- config_watermakOption.Value = config.SelectNodes("//configuration/watermarkOption")[0].InnerText.Trim();
- RadioButtonList1.Items[0].Text = ResourceManager.GetString("localupload");
- RadioButtonList1.Items[1].Text = ResourceManager.GetString("remoteupload");
- remoteupload.Text = ResourceManager.GetString("upload");
- }
- else if(config_type.Value == "File")
- {
- config_fileFilters.Value = config.SelectNodes("//configuration/fileFilters")[0].InnerText;
- }
- else if (config_type.Value == "Media")
- {
- config_fileFilters.Value = config.SelectNodes("//configuration/mediaFilters")[0].InnerText;
- }
- else if (config_type.Value == "Template")
- {
- config_fileFilters.Value = config.SelectNodes("//configuration/templateFilters")[0].InnerText;
- insertTemplate.Text = ResourceManager.GetString("inserttemplate");
- }
- config_maxAllUploadSize.Value = config.SelectNodes("//configuration/maxAllUploadSize")[0].InnerText.Trim();
- config_autoname.Value = config.SelectNodes("//configuration/autoname")[0].InnerText.Trim().ToLower();
- config_allowUpload.Value = config.SelectNodes("//configuration/allowUpload")[0].InnerText.Trim().ToLower();
- config_maxSingleUploadSize.Value = config.SelectNodes("//configuration/maxSingleUploadSize")[0].InnerText.Trim();
- config_fileListBox.Value=config.SelectNodes("//configuration/fileListBox")[0].InnerText;
- selectAllBtn.Text = ResourceManager.GetString("selectall");
- editBtn.Text = ResourceManager.GetString("rename");
- deleteBtn.Text = ResourceManager.GetString("delete");
- canceloading.Text = ResourceManager.GetString("canceloading");
- uploadBtn.Text = ResourceManager.GetString("upload");
-
- File_List.Columns[1].HeaderText = ResourceManager.GetString("filename");
- File_List.Columns[2].HeaderText = ResourceManager.GetString("creationtime");
- File_List.Columns[3].HeaderText = ResourceManager.GetString("filesize");
-
-
- if (config.SelectNodes("//configuration/delete")[0].InnerText == "false")
- deleteBtn.Enabled = false;
- if (config.SelectNodes("//configuration/edit")[0].InnerText == "false")
- editBtn.Enabled = false;
- if (config_fileListBox.Value=="false")
- File_List.Visible = false;
- maxSingleUploadSize.Text = Double.Parse(config_maxSingleUploadSize.Value) < 1024 ? config_maxSingleUploadSize.Value + "KB" : (Double.Parse(config_maxSingleUploadSize.Value) / 1024).ToString("f2") + "MB";
-
- if (Request.Cookies["uploadFolder"] != null)
- {
- path.Text = Server.UrlDecode(Request.Cookies["uploadFolder"].Value.ToLower());
- }
- if (path.Text=="" || config_allowUpload.Value != "true")
- {
- FileUpload1.Enabled = false;
- uploadBtn.Enabled = false;
- try
- {
- remoteupload.Enabled = false;
- remoteurl.Enabled = false;
- }
- catch
- {
- }
- space.Text = "0MB";
- useSpace.Text = "0MB";
- path.Text = "";
- File_List.Visible = false;
- deleteBtn.Enabled = false;
- editBtn.Enabled = false;
- selectAllBtn.Enabled = false;
- }
- else
- {
- vrPath = Server.MapPath(path.Text);
- if (!Directory.Exists(vrPath))
- Directory.CreateDirectory(vrPath);
- getDirSize(vrPath);
- }
- }
- }
- /// <summary>
- /// 返回目录里文件的空间使用量(MB)
- /// </summary>
- protected void getDirSize(string vrPath)
- {
- Double Size = 0;
- if (config_fileListBox.Value != "false")
- {
-
- DirectoryInfo d = new DirectoryInfo(vrPath);
- FileInfo[] fis = d.GetFiles();
- ArrayList showfile = new ArrayList();
- Array.Sort(fis,new SortFile());
- string[] Filters = config_fileFilters.Value.Split(',');
- foreach (FileInfo fi in fis)
- {
- Size += fi.Length;
- for (int i = 0; i <= Filters.Length - 1; i++)
- {
- if (fi.Extension.ToLower() == "." + Filters[i].ToString().ToLower())
- {
- showfile.Add(fi);
- break;
- }
- }
-
- }
- File_List.DataSource = showfile;
- File_List.DataBind();
- }
- Size = Convert.ToDouble((Double)Size / 1024);
- useSpace.Text = Size < 1024 ? Size.ToString("f1") + "KB" : (Size / 1024).ToString("f2") + "MB";
- space.Text = (Double.Parse(config_maxAllUploadSize.Value) - Size) < 1024 ? (Double.Parse(config_maxAllUploadSize.Value) - Size).ToString("f1") + "KB" : ((Double.Parse(config_maxAllUploadSize.Value) - Size) / 1024).ToString("f2") + "MB";
- uploadBtn.CommandArgument = Convert.ToString(Size);
- if (Size >= Double.Parse(config_maxAllUploadSize.Value))
- {
- FileUpload1.Enabled = false;
- uploadBtn.Enabled = false;
- }
- }
- /// <summary>
- /// 处理切换本地及远程上传的操作
- /// </summary>
- protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (RadioButtonList1.SelectedValue == "remote")
- {
- remoteupload.Visible = true;
- remoteurl.Visible = true;
- FileUpload1.Visible = false;
- uploadBtn.Visible = false;
-
- }
- else
- {
- remoteupload.Visible = false;
- remoteurl.Visible = false;
- FileUpload1.Visible = true;
- uploadBtn.Visible = true;
- }
- }
- /// <summary>
- /// 处理远程上传的操作
- /// </summary>
- protected void remoteupload_Click(object sender, EventArgs e)
- {
- if (remoteurl.Text!="")
- {
-
- //string name = FileUpload1.PostedFile.FileName;
- //FileInfo file = new FileInfo(name);
- string[] Filters = config_fileFilters.Value.Split(',');
- string[] afilename = remoteurl.Text.ToLower().Split('/');
-
- bool errortype = true;
- string[] bfilename = afilename[afilename.Length - 1].Split('.');
- string typeName = bfilename[bfilename.Length - 1].ToLower();
- //ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('"+typeName+"')", true);
- for (int i = 0; i <= Filters.Length - 1; i++)
- {
- if (typeName == Filters[i].ToString().ToLower())
- {
- errortype = false;
- break;
- }
- }
-
- if (!errortype)
- {
- HttpWebRequest hwq = (HttpWebRequest)WebRequest.Create(remoteurl.Text.ToLower());
- HttpWebResponse hwr = (HttpWebResponse)hwq.GetResponse();
- if (hwr.ContentLength < Double.Parse(config_maxSingleUploadSize.Value) * 1024 && Double.Parse(uploadBtn.CommandArgument) * 1024 + hwr.ContentLength < Double.Parse(config_maxAllUploadSize.Value) * 1024)
- {
- string uploadPath = path.Text;
- string fileName;
- if (config_autoname.Value == "true")
- {
- string y = DateTime.Now.Year.ToString();
- string m = DateTime.Now.Month.ToString();
- string d = DateTime.Now.Day.ToString();
- string h = DateTime.Now.Hour.ToString();
- string n = DateTime.Now.Minute.ToString();
- string s = DateTime.Now.Second.ToString();
- fileName = y + m + d + h + n + s;
- Random r = new Random();
- fileName = fileName + r.Next(1000);
- fileName = fileName + "."+typeName;
- }
- else
- {
- fileName = afilename[afilename.Length - 1];
- }
- string webFilePath = Server.MapPath(uploadPath + fileName);
- if (!File.Exists(webFilePath))
- {
- try
- {
- System.Drawing.Image bmp = System.Drawing.Image.FromStream(hwr.GetResponseStream());
- bmp.Save(webFilePath);
- if (config_watermark.Value == "true")
- {
- if (config_watermarkName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- watermarkText(Server.MapPath(uploadPath + "temp_" + fileName), webFilePath);
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- watermarkText(webFilePath, Server.MapPath(uploadPath + config_watermarkName.Value + fileName));
- }
- }
- else if (config_watermarkImages.Value == "true")
- {
- if (config_watermarkImagesName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- watermarkImages(Server.MapPath(uploadPath + "temp_" + fileName), webFilePath, Server.MapPath(config_watermarkImages_path.Value));
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- watermarkImages(webFilePath, Server.MapPath(uploadPath + config_watermarkImagesName.Value + fileName), Server.MapPath(config_watermarkImages_path.Value));
- }
- }
- if (config_smallImages.Value == "true")
- {
- if (config_smallImagesName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- MakeThumbnail(Server.MapPath(uploadPath + "temp_" + fileName), webFilePath, Int32.Parse(config_smallImagesW.Value), Int32.Parse(config_smallImagesH.Value), config_smallImagesType.Value);
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- MakeThumbnail(webFilePath, Server.MapPath(uploadPath + config_smallImagesName.Value + fileName), Int32.Parse(config_smallImagesW.Value), Int32.Parse(config_smallImagesH.Value), config_smallImagesType.Value);
- }
- }
- if (config_fileListBox.Value != "false")
- {
- getDirSize(Server.MapPath(uploadPath));
- }
- file_path.Text = uploadPath + fileName;
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("uploadsuccessful") + "')", true);
- }
- catch (Exception ex)
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("uploadfail") + ex.Message + "')", true);
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("exist") + "')", true);
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("overmaxsize") + "')", true);
- }
- hwr.Close();
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("errortype") + "')", true);
- }
- }
- }
- /// <summary>
- /// 处理本地上传的操作
- /// </summary>
- protected void UploadBtn_Click(object sender, EventArgs e)
- {
- if (FileUpload1.HasFile)
- {
- string name = FileUpload1.PostedFile.FileName;
- FileInfo file = new FileInfo(name);
- string[] Filters = config_fileFilters.Value.Split(',');
- bool errortype = true;
- string typeName = file.Extension.ToLower();
-
- for (int i = 0; i <= Filters.Length - 1; i++)
- {
- if (typeName == "."+Filters[i].ToString().ToLower())
- {
- errortype = false;
- break;
- }
- }
- if (!errortype)
- {
- if (FileUpload1.PostedFile.ContentLength < Double.Parse(config_maxSingleUploadSize.Value) * 1024 && Double.Parse(uploadBtn.CommandArgument) * 1024 + FileUpload1.PostedFile.ContentLength < Double.Parse(config_maxAllUploadSize.Value) * 1024)
- {
- string uploadPath = path.Text;
- string fileName;
- if (config_autoname.Value == "true")
- {
- string y = DateTime.Now.Year.ToString();
- string m = DateTime.Now.Month.ToString();
- string d = DateTime.Now.Day.ToString();
- string h = DateTime.Now.Hour.ToString();
- string n = DateTime.Now.Minute.ToString();
- string s = DateTime.Now.Second.ToString();
- fileName = y + m + d + h + n + s;
- Random r = new Random();
- fileName = fileName + r.Next(1000);
- fileName = fileName + typeName;
- }
- else
- {
- fileName = file.Name;
- }
- string webFilePath = Server.MapPath(uploadPath + fileName);
- if (!File.Exists(webFilePath))
- {
- try
- {
- FileUpload1.SaveAs(webFilePath);
- if (config_watermark.Value == "true")
- {
- if (config_watermarkName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- watermarkText(Server.MapPath(uploadPath + "temp_" + fileName), webFilePath);
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- watermarkText(webFilePath,Server.MapPath(uploadPath + config_watermarkName.Value + fileName));
- }
- }
- else if (config_watermarkImages.Value == "true")
- {
- if (config_watermarkImagesName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- watermarkImages(Server.MapPath(uploadPath + "temp_" + fileName),webFilePath, Server.MapPath(config_watermarkImages_path.Value));
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- watermarkImages(webFilePath, Server.MapPath(uploadPath + config_watermarkImagesName.Value + fileName), Server.MapPath(config_watermarkImages_path.Value));
- }
- }
- if (config_smallImages.Value == "true")
- {
- if (config_smallImagesName.Value == "false")
- {
- File.Move(webFilePath, Server.MapPath(uploadPath + "temp_" + fileName));
- MakeThumbnail(Server.MapPath(uploadPath + "temp_" + fileName), webFilePath, Int32.Parse(config_smallImagesW.Value),Int32.Parse(config_smallImagesH.Value), config_smallImagesType.Value);
- File.Delete(Server.MapPath(uploadPath + "temp_" + fileName));
- }
- else
- {
- MakeThumbnail(webFilePath, Server.MapPath(uploadPath + config_smallImagesName.Value + fileName), Int32.Parse(config_smallImagesW.Value), Int32.Parse(config_smallImagesH.Value), config_smallImagesType.Value);
- }
- }
- if (config_fileListBox.Value != "false")
- {
- getDirSize(Server.MapPath(uploadPath));
- }
- file_path.Text = uploadPath + fileName;
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("uploadsuccessful") + "')", true);
- }
- catch (Exception ex)
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("uploadfail") + ex.Message + "')", true);
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("exist") + "')", true);
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("overmaxsize") + "')", true);
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('" + ResourceManager.GetString("errortype") + "')", true);
- }
- }
- }
- /// <summary>
- /// 处理缩略图操作
- /// </summary>
- public void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
- {
- System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);
- int towidth = width;
- int toheight = height;
- int x = 0;
- int y = 0;
- int ow = originalImage.Width;
- int oh = originalImage.Height;
- switch (mode)
- {
- case "HW"://指定高宽缩放(可能变形)
- break;
- case "W"://指定宽,高按比例
- toheight = originalImage.Height * width / originalImage.Width;
- break;
- case "H"://指定高,宽按比例
- towidth = originalImage.Width * height / originalImage.Height;
- break;
- case "Cut"://指定高宽裁减(不变形)
- if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
- {
- oh = originalImage.Height;
- ow = originalImage.Height * towidth / toheight;
- y = 0;
- x = (originalImage.Width - ow) / 2;
- }
- else
- {
- ow = originalImage.Width;
- oh = originalImage.Width * height / towidth;
- x = 0;
- y = (originalImage.Height - oh) / 2;
- }
- break;
- default:
- break;
- }
- //新建一个bmp图片
- System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
- //新建一个画板
- System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
- //设置高质量插值法
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
- //设置高质量,低速度呈现平滑程度
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- //清空画布并以透明背景色填充
- g.Clear(System.Drawing.Color.Transparent);
- //在指定位置并且按指定大小绘制原图片的指定部分
- g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
- new System.Drawing.Rectangle(x, y, ow, oh),
- System.Drawing.GraphicsUnit.Pixel);
- try
- {
- //以jpg格式保存缩略图
- bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- catch (System.Exception e)
- {
- throw e;
- }
- finally
- {
- originalImage.Dispose();
- bitmap.Dispose();
- g.Dispose();
- }
- }
- /// <summary>
- /// 处理文字水印的操作
- /// </summary>
- protected void watermarkText(string Path,string newPath)
- {
- System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
- try
- {
- System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
- g.DrawImage(image, 0, 0, image.Width, image.Height);
- System.Drawing.Font f = new System.Drawing.Font("System", 12);
- System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
- int x, y;
- if (inputx.Enabled && inputy.Enabled)
- {
- x = Int32.Parse(inputx.Text);
- y = Int32.Parse(inputy.Text);
- }
- else
- {
- x = 15;
- y = 15;
- }
- g.DrawString(config_watermarkText.Value, f, b, x, y);
- g.Dispose();
- image.Save(newPath);
- image.Dispose();
- }
- catch
- {
- image.Save(newPath);
- image.Dispose();
- }
-
- }
- /// <summary>
- /// 处理图片水印的操作
- /// </summary>
- protected void watermarkImages(string Path,string newPath,string images_path)
- {
- System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
- System.Drawing.Image copyImage = System.Drawing.Image.FromFile(images_path);
- try
- {
- System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
- int x, y;
- if (inputx.Enabled && inputy.Enabled)
- {
- x = Int32.Parse(inputx.Text);
- y = Int32.Parse(inputy.Text);
- }
- else
- {
- x = 0;
- y = 0;
- }
- g.DrawImage(copyImage, new System.Drawing.Rectangle(x,y, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
- //g.DrawImage(copyImage, new System.Drawing.Rectangle(image.Width - copyImage.Width-x, image.Height - copyImage.Height-y, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
- g.Dispose();
- image.Save(newPath);
- image.Dispose();
- }
- catch
- {
- image.Save(newPath);
- image.Dispose();
- }
- }
- /// <summary>
- /// 处理全选的操作
- /// </summary>
- protected void checkAll(object sender, EventArgs e)
- {
- CheckBox cb = (CheckBox)sender;
- if (cb.Text == ResourceManager.GetString("selectall"))
- {
- foreach (GridViewRow gvr in File_List.Rows)
- {
- CheckBox cb1 = (CheckBox)gvr.FindControl("check");
- cb1.Checked = cb.Checked;
- }
- if (cb.Checked)
- {
- selectAllBtn.Text = ResourceManager.GetString("unselect");
- }
- else
- {
- selectAllBtn.Text = ResourceManager.GetString("selectall");
- }
- }
- }
- /// <summary>
- /// 处理全选按键的操作
- /// </summary>
- protected void selectAllBtn_Click(object sender, EventArgs e)
- {
- try
- {
- if (selectAllBtn.Text == ResourceManager.GetString("selectall"))
- {
- CheckBox cb = (CheckBox)File_List.HeaderRow.FindControl("checkall");
- cb.Checked = true;
- foreach (GridViewRow gvr in File_List.Rows)
- {
- CheckBox cb1 = (CheckBox)gvr.FindControl("check");
- cb1.Checked = true;
- }
- selectAllBtn.Text = ResourceManager.GetString("unselect");
- }
- else
- {
- CheckBox cb = (CheckBox)File_List.HeaderRow.FindControl("checkall");
- cb.Checked = false;
- foreach (GridViewRow gvr in File_List.Rows)
- {
- CheckBox cb1 = (CheckBox)gvr.FindControl("check");
- cb1.Checked = false;
- }
- selectAllBtn.Text = ResourceManager.GetString("selectall");
- }
- }
- catch
- {
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "alert('"+ResourceManager.GetString("noselect")+"')", true);
- }
- }
- /// <summary>
- /// 处理插入模板的操作
- /// </summary>
- protected void insertTemplate_Click(object sender, EventArgs e)
- {
- if (file_path.Text != "")
- {
- string line;
- StringBuilder strhtml = new StringBuilder();
- StreamReader sr = new StreamReader(Server.UrlDecode(HttpContext.Current.Request.Cookies["configpath"].Value)+file_path.Text.ToLower(), System.Text.Encoding.Default);
- while ((line = sr.ReadLine()) != null)
- {
- strhtml.Append(line);
- }
- sr.Close();
- templateContent.Value = strhtml.ToString();
- ClientScript.RegisterStartupScript(typeof(Page), "Key", "insertTemplate();", true);
- }
- }
- /// <summary>
- /// 处理删除按键的操作
- /// </summary>
- protected void deleteBtn_Click(object sender, EventArgs e)
- {
- foreach (GridViewRow dl in File_List.Rows)
- {
- CheckBox cb = (CheckBox)dl.FindControl("check");
- if (cb.Checked)
- {
- GridViewRow row = (GridViewRow)cb.NamingContainer;
- File.Delete(Server.MapPath(path.Text + (File_List.Rows[row.RowIndex].FindControl("ListID") as Label).Text));
- }
- }
-
- getDirSize(Server.MapPath(path.Text));
- }
- /// <summary>
- /// 处理重命名按键的操作
- /// </summary>
- protected void editBtn_Click(object sender, EventArgs e)
- {
- foreach (GridViewRow dl in File_List.Rows)
- {
- CheckBox cb = (CheckBox)dl.FindControl("check");
- if (cb.Checked)
- {
- GridViewRow row = (GridViewRow)cb.NamingContainer;
- File_List.EditIndex = row.RowIndex;
- getDirSize(Server.MapPath(path.Text));
- (File_List.Rows[File_List.EditIndex].FindControl("editName") as TextBox).Focus();
- break;
- }
- }
- }
- /// <summary>
- /// 处理全部不选的操作
- /// </summary>
- protected void File_List_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
- {
- File_List.EditIndex = -1;
- getDirSize(Server.MapPath(path.Text));
- }
- /// <summary>
- /// 处理重命名操作
- /// </summary>
- protected void File_List_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
- string oldname = (File_List.Rows[e.RowIndex].FindControl("editBtn") as Button).CommandArgument;
- string[] typename = oldname.Split('.');
- File.Move(Server.MapPath(path.Text + oldname), Server.MapPath(path.Text) + (File_List.Rows[e.RowIndex].FindControl("editName") as TextBox).Text.Replace(""", string.Empty).Replace("/", string.Empty).Replace("\", string.Empty) + "." + typename[typename.Length - 1].ToLower());
- File_List.EditIndex = -1;
- getDirSize(Server.MapPath(path.Text));
- }
- }
- #endregion
- }