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

📄 fileworkerbase.cs

📁 这是一个简单的论坛程序源码
💻 CS
字号:
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: FileWorkerBase.cs
 * 	Base class used by the FileBrowserConnector and Uploader.
 * 
 * File Authors:
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 */

using System;

namespace FredCK.FCKeditorV2
{
    public abstract class FileWorkerBase : System.Web.UI.Page
    {
        private const string DEFAULT_USER_FILES_PATH = "/UserFiles/";
        private const string DEFAULT_UPLOAD_DENIED_EXTENSIONS = ".php|.php3|.php5|.phtml|.asp|.aspx|.ascx|.jsp|.cfm|.cfc|.pl|.bat|.exe|.dll|.reg|.cgi|.cs|.vb|.asa|.cer|c.dx|.ascx|.asax|.ashx|.asmx|.java|.jsl";

        private string sUserFilesPath;
        private string sUserFilesDirectory;
        private string sUploadDeniedExtensions;

        protected string UserFilesPath
        {
            get
            {
                if (sUserFilesPath == null)
                {
                    // Try to get from the "Application".
                    sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"];

                    // Try to get from the "Session".
                    if (sUserFilesPath == null || sUserFilesPath.Length == 0)
                    {
                        //这句话由我注视,因为如果当前页面或应用程序的EnableSessionState被设置为False时,这句话会抛出异常。
                        //sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"];

                        // Try to get from the Web.config file.
                        if (sUserFilesPath == null || sUserFilesPath.Length == 0)
                        {
                            sUserFilesPath = System.Configuration.ConfigurationManager.AppSettings["FCKeditor:UserFilesPath"];

                            // Otherwise use the default value.
                            if (sUserFilesPath == null || sUserFilesPath.Length == 0)
                                sUserFilesPath = DEFAULT_USER_FILES_PATH;

                            // Try to get from the URL.
                            if (sUserFilesPath == null || sUserFilesPath.Length == 0)
                            {
                                sUserFilesPath = Request.QueryString["ServerPath"];
                            }
                        }
                    }

                    // Check that the user path ends with slash ("/")
                    if (!sUserFilesPath.EndsWith("/"))
                        sUserFilesPath += "/";
                    ////ResolveUrl  add by tupunco 2006-10-9
                    if (sUserFilesPath.StartsWith("~"))
                        sUserFilesPath = this.ResolveUrl(sUserFilesPath);
                }
                return sUserFilesPath;
            }
        }

        /// <summary>
        /// The absolution path (server side) of the user files directory. It 
        /// is based on the <see cref="FileWorkerBase.UserFilesPath"/>.
        /// </summary>
        protected string UserFilesDirectory
        {
            get
            {
                if (sUserFilesDirectory == null)
                {
                    // Get the local (server) directory path translation.
                    sUserFilesDirectory = Server.MapPath(this.UserFilesPath);
                }
                return sUserFilesDirectory;
            }
        }

        /// <summary>
        /// Denied File's Extensions
        /// 不被允许的文件扩展名
        /// AppSettings["FCKeditor:UploadDeniedExtensions"]
        /// 适用方法可以参看UserFilesPath属性设置方法
        /// </summary>
        public string UploadDeniedExtensions
        {
            get
            {
                if (sUploadDeniedExtensions == null)
                {
                    // Try to get from the "Application".
                    sUploadDeniedExtensions = (string)Application["FCKeditor:UploadDeniedExtensions"];

                    // Try to get from the "Session".
                    if (sUploadDeniedExtensions == null || sUploadDeniedExtensions.Length == 0)
                    {
                        //这句话由我注视,因为如果当前页面或应用程序的EnableSessionState被设置为False时,这句话会抛出异常。
                        //sUploadDeniedExtensions = (string)Session["FCKeditor:UploadDeniedExtensions"];

                        // Try to get from the Web.config file.
                        if (sUploadDeniedExtensions == null || sUploadDeniedExtensions.Length == 0)
                        {
                            sUploadDeniedExtensions = System.Configuration.ConfigurationManager.AppSettings["FCKeditor:UploadDeniedExtensions"];

                            // Otherwise use the default value.
                            if (sUploadDeniedExtensions == null || sUploadDeniedExtensions.Length == 0)
                                sUploadDeniedExtensions = DEFAULT_UPLOAD_DENIED_EXTENSIONS;
                        }
                    }
                }
                return sUploadDeniedExtensions;
            }
        }
        /// <summary>
        /// Check Can Upload this file
        /// 判断文件类型是否可以上传
        /// </summary>
        /// <param name="sFileName">will upload file's name将要上传的文件名</param>
        /// <returns></returns>
        public bool CheckUploadFileExtension(string sFileName)
        {
            //Denied Extensions Array
            //不被允许的文件扩展名数组
            string[] aExtensions = this.UploadDeniedExtensions.Split(new char[] { '|' });
            //将要上传的文件扩展名
            string fileEx = System.IO.Path.GetExtension(sFileName);
            foreach (string ex in aExtensions)
            {
                if (ex == fileEx)
                    return false;
            }
            return true;
        }
    }
}

⌨️ 快捷键说明

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