コード例 #1
0
        private Guid AddUnsortedAttachment(TreeNode page, string requestFileName)
        {
            if (!(Request.Files[requestFileName] is HttpPostedFileWrapper file))
            {
                return(Guid.Empty);
            }

            return(ImageUploaderHelper.Upload(file, path =>
            {
                return DocumentHelper.AddUnsortedAttachment(page, Guid.Empty, path).AttachmentGUID;
            }));
        }
コード例 #2
0
        private Guid AddMediaFile(string requestFileName, MediaLibraryInfo library)
        {
            if (!(Request.Files[requestFileName] is HttpPostedFileWrapper file))
            {
                return(Guid.Empty);
            }

            return(ImageUploaderHelper.Upload(file, path =>
            {
                var mediaFile = new MediaFileInfo(path, library.LibraryID);
                MediaFileInfoProvider.SetMediaFileInfo(mediaFile);

                return mediaFile.FileGUID;
            }));
        }
コード例 #3
0
        /// <summary>
        /// Uploads given file.
        /// </summary>
        /// <param name="file">Posted file.</param>
        /// <param name="storeFile">Action to store the file.</param>
        public static Guid Upload(HttpPostedFileWrapper file, Func <string, Guid> storeFile)
        {
            var imagePath = ImageUploaderHelper.GetTempFilePath(file);

            byte[] data = new byte[file.ContentLength];
            file.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
            file.InputStream.Read(data, 0, file.ContentLength);

            File.WriteAllBytes(imagePath, data);

            var fileGuid = storeFile(imagePath);

            File.Delete(imagePath);

            return(fileGuid);
        }