📄 uploadsingle.ascx.cs
字号:
namespace Seaskyer.WebApp.skyNews.Pages.UserMSC
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Seaskyer.Strings;
using Seaskyer.WebApp.Utility;
/// <summary>
/// UploadSingle : 单文件上传。
/// </summary>
public class UploadSingle : basePage
{
protected Panel uploadPanel, resultPanel;
protected Label label;
protected HtmlInputButton Submit1;
private void Page_Load(object sender, System.EventArgs e)
{
if( !power.GPB("usermsc/upload.ascx", "Enable") )
{
label.Text = "您无权执行 “" + lang["usermsc/upload.ascx", "@AppName"] + "” 操作";
resultPanel.Visible = true;
return;
}
InitPage();
uploadPanel.Visible = true;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
}
private void InitPage()
{
uploadPanel.Visible = false;
resultPanel.Visible = false;
}
#endregion
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
InitPage();
// 单文件上传
HttpPostedFile upFile = Request.Files[0];
string fileType = config["uploadType"];
int fileSize = int.Parse(config["uploadSize"]) * 1024;
string uploadSavePath = user.UploadSavePath;
string timePath = String.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HH"));
string userFilePath = String.Format("{0}/{1}/", user.userID, timePath);
string savePath = uploadSavePath + userFilePath;
string returnPath = mp.GetWebFilePath(config) + userFilePath;
string[] uploadInfo = WebUtility.UploadFile(upFile, fileType, fileSize, false, savePath);
label.Text = "文件上传" + uploadInfo[4];
resultPanel.Visible = true;
if( uploadInfo[4] == "成功" )
{
Response.Write("<" + "script>var str = ('" + uploadInfo[1] + "'); if(parent.document.all['url'] != null)parent.document.all['url'].value = '" + returnPath + uploadInfo[1] + "';</" + "script>\n");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -