Exemple #1
0
 public FilesystemUploadedFile(FilesystemUploadStorageProvider provider,
                               string controlUniqueID, string fileName, string contentType,
                               UploadStorageConfig storageConfig)
     : base(controlUniqueID, fileName, contentType)
 {
     Initialize(provider, controlUniqueID, fileName, contentType, storageConfig);
 }
        public FilesystemUploadedFile(FilesystemUploadStorageProvider provider, 
		                                string controlUniqueID, string fileName, string contentType,
		                                UploadStorageConfig storageConfig)
            : base(controlUniqueID, fileName, contentType)
        {
            Initialize(provider, controlUniqueID, fileName, contentType, storageConfig);
        }
 public virtual UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName,
                                                string contentType, UploadStorageConfig storageConfig)
 {
     if (storageConfig != null && storageConfig.Count != 0)
     {
         throw new ApplicationException(this.Name + " doesn't understand InputFile.StorageConfig.");
     }
     return(this.CreateUploadedFile(context, controlUniqueID, fileName, contentType));
 }
        public virtual UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName,
		                                                  string contentType, UploadStorageConfig storageConfig)
        {
            if (storageConfig != null && storageConfig.Count != 0)
              	{
              		throw new ApplicationException(this.Name + " doesn't understand InputFile.StorageConfig.");
              	}
              	return this.CreateUploadedFile(context, controlUniqueID, fileName, contentType);
        }
Exemple #5
0
        /// <summary>
        /// Creates and returns a new <see cref="UploadStorageConfig"/> (or
        /// subclass) for use with the current request.
        /// </summary>
        /// <returns>a new <see cref="UploadStorageConfig"/> or subclass.</returns>
        /// <remarks>If the installed module does not explicitly support
        /// creating <see cref="UploadStorageConfig"/> objects, this method returns
        /// the <see cref="UploadStorageConfig"/> created by the currently selected
        /// <see cref="UploadStorageProvider"/>.</remarks>
        public static UploadStorageConfig CreateUploadStorageConfig()
        {
            UploadStorageConfig storageConfig = InstalledModule.CreateUploadStorageConfig();

            if (storageConfig == null)
            {
                storageConfig = UploadStorage.CreateUploadStorageConfig();
            }
            return(storageConfig);
        }
Exemple #6
0
        public static UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName,
                                                      string contentType, UploadStorageConfig storageConfig)
        {
            UploadedFile file = null;

            if (storageConfig == null || storageConfig.Count == 0)
            {
                file = Provider.CreateUploadedFile(context, controlUniqueID, fileName, contentType);
            }
            else
            {
                file = Provider.CreateUploadedFile(context, controlUniqueID, fileName, contentType, storageConfig);
            }
            return(file);
        }
Exemple #7
0
        public static UploadedFile ConvertToUploadedFile(string controlUniqueID, HttpPostedFile file)
        {
            // We use a temporary UploadContext so that we have something we can pass to the
            // UploadStorageProvider.  Note that unlike when the UploadHttpModule is used,
            // this temporary context is not shared between uploaded files.
            UploadContext ctx = new UploadContext();

            ctx._ContentLength = HttpContext.Current.Request.ContentLength;
            UploadStorageConfig storageConfig = UploadStorage.CreateUploadStorageConfig();
            string storageConfigString
                = HttpContext.Current.Request.Form[Constants.ConfigNamePrefix + "-" + controlUniqueID];

            if (storageConfigString != null && storageConfigString != string.Empty)
            {
                storageConfig.Unprotect(storageConfigString);
            }
            UploadedFile uploadedFile
                = UploadStorage.CreateUploadedFile(ctx, controlUniqueID, file.FileName, file.ContentType, storageConfig);

            System.IO.Stream outStream = null, inStream = null;
            try
            {
                outStream = uploadedFile.CreateStream();
                inStream  = file.InputStream;
                byte[] buf       = new byte[4096];
                int    bytesRead = -1;
                while (outStream.CanWrite && inStream.CanRead &&
                       (bytesRead = inStream.Read(buf, 0, buf.Length)) > 0)
                {
                    outStream.Write(buf, 0, bytesRead);
                }
            }
            finally
            {
                if (inStream != null)
                {
                    inStream.Close();
                }
                if (outStream != null)
                {
                    outStream.Close();
                }
            }
            return(uploadedFile);
        }
Exemple #8
0
        private void Initialize(FilesystemUploadStorageProvider provider,
                                string controlUniqueID, string fileName, string contentType,
                                UploadStorageConfig storageConfig)
        {
            DirectoryInfo tmpDirInfo = provider.GetTempDirectory(storageConfig);

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("tmpDirInfo={0}", tmpDirInfo.FullName);
            }
            if (!tmpDirInfo.Exists)
            {
                tmpDirInfo.Create();
            }
            string name = Guid.NewGuid().ToString("N"); // 32 hex digits

            name        = name + ".config";             // ASP.NET blocks requests for .config files.
            tmpFileName = Path.Combine(tmpDirInfo.FullName, name);
            TmpFile     = new FileInfo(tmpFileName);
        }
Exemple #9
0
 public override UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName, string contentType, UploadStorageConfig storageConfig)
 {
     return(new FilesystemUploadedFile(this, controlUniqueID, fileName, contentType, storageConfig));
 }
 public override UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName, string contentType, UploadStorageConfig storageConfig)
 {
     return new FilesystemUploadedFile(this, controlUniqueID, fileName, contentType, storageConfig);
 }
        private void Initialize(SqlServerUploadStorageProvider provider,
                                        UploadStorageConfig storageConfig)
        {
            //Simply store the provider, the SqlServerBlobStream takes care of everything else (i hope)
            _provider = provider;

            // If hash algorithm is specified, create an object to calculate hash
            if (provider.HashAlgorithm != null && provider.HashAlgorithm.Length > 0){
                _hashName = provider.HashAlgorithm;
                _hashAlgorithm = System.Security.Cryptography.HashAlgorithm.Create(provider.HashAlgorithm);
            }
        }
Exemple #12
0
        public static UploadedFile CreateUploadedFile(UploadContext context, string controlUniqueID, string fileName,
		                                              string contentType, UploadStorageConfig storageConfig)
        {
            UploadedFile file = null;
            if (storageConfig == null || storageConfig.Count == 0)
            {
                file = Provider.CreateUploadedFile(context, controlUniqueID, fileName, contentType);
            }
            else
            {
                file = Provider.CreateUploadedFile(context, controlUniqueID, fileName, contentType, storageConfig);
            }
            return file;
        }
        private void Initialize(FilesystemUploadStorageProvider provider, 
		                                string controlUniqueID, string fileName, string contentType,
		                                UploadStorageConfig storageConfig)
        {
            DirectoryInfo tmpDirInfo = provider.GetTempDirectory(storageConfig);
            if (log.IsDebugEnabled) log.DebugFormat("tmpDirInfo={0}", tmpDirInfo.FullName);
            if (!tmpDirInfo.Exists)
            {
                tmpDirInfo.Create();
            }
            string name = Guid.NewGuid().ToString("N"); // 32 hex digits
            name = name + ".config"; // ASP.NET blocks requests for .config files.
            tmpFileName = Path.Combine(tmpDirInfo.FullName, name);
            TmpFile = new FileInfo(tmpFileName);
        }