UCPictureAdd.ascx.cs代码

using System;
using System.IO;
using HoverTree.HoverTreeFrame.HtImage;
using HoverTree.HoverTreeFrame.HtString;
using HoverTreeTop.HtConfig.HtTemporary;
using HoverTreeTop.HtModel.HtInfo;

namespace HoverTreeTop.HoverTree.HoverTreePanel.HTPanel.HControl
{
public delegate void OperateSuccessHanlder(string fileName); //创建委托

public partial class UCPictureAdd : System.Web.UI.UserControl
{
//public string PictureFileName="";

public event OperateSuccessHanlder OperateSuccess;

void OnOperateSuccess(string fileName)
{
OperateSuccess?.Invoke(fileName);
}
protected void Page_Load(object sender, EventArgs e)
{

}

protected void button_hewenqi_Click(object sender, EventArgs e)
{
HtPictureInfo h_info = new HtPictureInfo();
h_info.HtSuffix = HoverTreeImageTool.GetGpjImageFileExtension(fileUpload_hovertree.PostedFile.ContentType);
if (h_info.HtSuffix == "")
{
literal_tips.Text = "请选择jpg,png或者gif图片文件";
return;
}

if (fileUpload_hovertree.PostedFile.ContentLength > 1048576)
{
literal_tips.Text = "选择的文件太大。";
return;
}
h_info.HtTitle = "";
h_info.HtSourceUrl = "";
h_info.HtFileName = HoverString.GetHoverTreeString();
h_info.HtAddTime = DateTime.Now;
h_info.HtFolder = HoverString.HovertConvert(h_info.HtAddTime.ToString("yyyyMM"));
literal_tips.Text = HtBll.HtPicture.Add(h_info);
if (literal_tips.Text == string.Empty)
{
OnOperateSuccess(h_info.HtFileName);
literal_fileName.Text = h_info.HtFileName;
//PictureFileName = h_info.HtFileName;
literal_tips.Text = "图片记录添加成功";
string h_fullName = TempConfig.PictureUpPath + h_info.HtFolder + "\\" + h_info.HtFileName + "." + h_info.HtSuffix;
try
{
FileInfo h_fileInfo = new FileInfo(h_fullName);
if (!h_fileInfo.Directory.Exists)
Directory.CreateDirectory(h_fileInfo.DirectoryName);
fileUpload_hovertree.SaveAs(h_fullName);
literal_tips.Text = literal_tips.Text + ",图片上传成功。";
}
catch { literal_tips.Text = literal_tips.Text + ",图片上传失败。"; }
}
else
{
literal_fileName.Text = "";
//PictureFileName = "";
}
}
}
}