⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadhelper.cs

📁 上传的控件
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace WUSGControl.Web.Upload
{
    /// <summary>
    /// 上传帮助类器,提供和上传有关的周边的方法
    /// </summary>
    public class UploadHelper
    {

        #region Filds

        private string guid;
        
        

        #endregion

        #region Properties      

        #endregion

        public UploadHelper()
        {            
            
        }

        /// <summary>
        /// Get a uploaded file.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static UploadFile GetUploadFile(string name)
        {
            UploadFile uploadFile = new UploadFile(name);

            return (uploadFile.FileName == string.Empty) ? null : uploadFile;
        }


        /// <summary>
        /// Get all uploaded files.返回上传文件集合
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static UploadFileCollection GetUploadFileList(string name)
        {
            UploadFileCollection uploadFiles = new UploadFileCollection();
            //Request[name]是在哪里配置的呢?当多文件上传时多个Input提交到服务器上通过files可以获得,多文件方式有用
            string content = Utils.GetContext().Request[name];
            if ((content == null) || (content == string.Empty))
            {
                return uploadFiles;
            }
            else
            {
                string[] contentArray = content.Split(',');
                //Utils.2writem("("contentarray长度为" + contentArray.Length);
                for (int i = 0; i < contentArray.Length; i++)
                {
                    string curContent = contentArray[i];
                    if (!string.IsNullOrEmpty(curContent)) 
                        uploadFiles.Add(new UploadFile(curContent));
                }

            }

            return uploadFiles;
        }

        /// <summary>
        /// Register progress bar to a button.
        /// </summary>
        /// <param name="uploadButton"></param>
        /// <param name="causesValidation"></param>
        public void RegisterProgressBar(Button uploadButton)
        {            
            this.guid = Guid.NewGuid().ToString();
            Page page = (Page)Utils.GetContext().CurrentHandler;
            
            //注册一个随机ID,在和按钮邦定时产生的.注册一个隐藏控件.
             page.RegisterHiddenField("Sunrise_Web_Upload_UploadGUID", this.guid);

            UploadStatus uploadStatus = new UploadStatus();
            page.Application.Add(("_UploadGUID_" + this.guid), uploadStatus);
        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -