コード例 #1
0
        public TypeConfig this[string typeName]
        {
            get
            {
                if (!_Types.Contains(typeName))
                {
                    _Types[typeName] = new TypeConfig(_FileWorker);
                }

                return((TypeConfig)_Types[typeName]);
            }
        }
コード例 #2
0
        protected string ServerMapFolder(string resourceType, string folderPath, bool isQuickUpload)
        {
            TypeConfig typeConfig = this.Config.TypeConfig[resourceType];

            // Get the resource type directory.
            string sResourceTypePath = isQuickUpload ? typeConfig.GetQuickUploadDirectory() : typeConfig.GetFilesDirectory();

            // Ensure that the directory exists.
            Util.CreateDirectory(sResourceTypePath);

            // Return the resource type directory combined with the required path.
            return(System.IO.Path.Combine(sResourceTypePath, folderPath.TrimStart('/')));
        }
コード例 #3
0
        protected void FileUpload(string resourceType, string currentFolder, bool isQuickUpload)
        {
            HttpPostedFile oFile = Request.Files["NewFile"];

            string sFileName = "";

            if (oFile == null)
            {
                this.SendFileUploadResponse(202, isQuickUpload);
                return;
            }

            // Map the virtual path to the local server path.
            string sServerDir = this.ServerMapFolder(resourceType, currentFolder, isQuickUpload);

            // Get the uploaded file name.
            sFileName = System.IO.Path.GetFileName(oFile.FileName);
            sFileName = this.SanitizeFileName(sFileName);

            string sExtension = System.IO.Path.GetExtension(oFile.FileName);

            sExtension = sExtension.TrimStart('.');

            if (!this.Config.TypeConfig[resourceType].CheckIsAllowedExtension(sExtension))
            {
                this.SendFileUploadResponse(202, isQuickUpload);
                return;
            }

            if (this.Config.CheckIsNonHtmlExtension(sExtension) && !this.CheckNonHtmlFile(oFile))
            {
                this.SendFileUploadResponse(202, isQuickUpload);
                return;
            }

            int iErrorNumber = 0;
            int iCounter     = 0;

            while (true)
            {
                string sFilePath = System.IO.Path.Combine(sServerDir, sFileName);

                if (System.IO.File.Exists(sFilePath))
                {
                    iCounter++;
                    sFileName =
                        System.IO.Path.GetFileNameWithoutExtension(oFile.FileName) +
                        "(" + iCounter + ")." +
                        sExtension;

                    iErrorNumber = 201;
                }
                else
                {
                    oFile.SaveAs(sFilePath);
                    break;
                }
            }

            TypeConfig typeConfig = this.Config.TypeConfig[resourceType];

            string sFileUrl = isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath();

            sFileUrl += sFileName;

            this.SendFileUploadResponse(iErrorNumber, isQuickUpload, sFileUrl, sFileName);
        }