📄 uploadimageineditor.cs
字号:
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Security;
using System.Configuration;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NetFocus.Web.Applications.Forum
{
public class UploadImageInEditor : SkinedControl
{
private FileUpload fu;
private Button btnUpload;
private Literal lblOK;
protected override void AttachChildControls()
{
fu = (FileUpload)FindControl("fu");
btnUpload = (Button)FindControl("btnUpload");
lblOK = (Literal)FindControl("lblOK");
if (btnUpload != null)
{
btnUpload.Click += new EventHandler(btnUpload_Click);
}
}
private void btnUpload_Click(Object sender, EventArgs e)
{
if (fu.HasFile)
{
FileUploader thefu = new FileUploader();
try
{
thefu.CreatDirectory = bool.Parse(ConfigurationManager.AppSettings["AutoCreateDirectory"]);
}
catch
{
Exception ex = new Exception("AutoCreateDirectory值错误!");
throw ex;
}
thefu.FileType = ConfigurationManager.AppSettings["FileTypes"];
try
{
thefu.NeedWaterMark = bool.Parse(ConfigurationManager.AppSettings["NeedWarterMark"]);
}
catch
{
Exception ex = new Exception("NeedWarterMark值错误!");
throw ex;
}
thefu.Path = ConfigurationManager.AppSettings["StorageFolder"];
thefu.Sizes = int.Parse(ConfigurationManager.AppSettings["FileSizeLimit"]);
string src = thefu.Save(fu);
if (src != null && src != "0")
{
//循环处理发送url到文本框
string[] targetInput = ConfigurationManager.AppSettings["TargetInputID"].Split(',');
for (int scriptIndex = 0; scriptIndex <= targetInput.GetUpperBound(0); scriptIndex++)
{
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "send" + scriptIndex.ToString(),
"<script language=\"javascript\">window.parent.document.getElementById('" +
targetInput[scriptIndex] +
"').value='" + src + "'</script>");
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "focus" + scriptIndex.ToString(),
"<script language=\"javascript\">window.parent.document.getElementById('" +
targetInput[scriptIndex] +
"').focus()</script>");
}
fu.Visible = false;
btnUpload.Visible = false;
lblOK.Text = "文件已成功上传!";
}
else
{
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error",
"<script language=\"javascript\">alert('上传失败,请检查:\\n1.站点设置是否正确?\\n2.目标目录是否有可写权限?\\n3.文件类型是否是允许的类型?\\n4.文件大小是否超出了限制(最大" +
ConfigurationManager.AppSettings["FileSizeLimit"] + "KB)? ')</script>");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -