public override Stream GetOutputStream(UploadedFile file)
        {
            FileStream fileS = null;
            ZipOutputStream zipS = null;

            try
            {
                string outputPath = GetZipPath(file);

                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

                fileS = File.OpenWrite(outputPath);
                zipS = new ZipOutputStream(fileS);

                zipS.SetLevel(5);

                zipS.PutNextEntry(new ZipEntry(file.ClientName));

                file.LocationInfo[FileNameKey] = outputPath;

                return zipS;
            }
            catch
            {
                if (fileS != null)
                    fileS.Close();

                if (zipS != null)
                    zipS.Close();

                return null;
            }
        }
        public override Stream GetWriteStream(UploadedFile file)
        {
            file.ServerLocation = Path.Combine(HttpContext.Current.Server.MapPath(_location), Path.GetFileNameWithoutExtension(GetValidFileName(file.ClientName)) + ".zip");

            Directory.CreateDirectory(Path.GetDirectoryName(file.ServerLocation));

            FileStream fileS = null;
            ZipOutputStream zipS = null;

            try
            {
                fileS = File.OpenWrite(file.ServerLocation);
                zipS = new ZipOutputStream(fileS);

                zipS.SetLevel(5);

                zipS.PutNextEntry(new ZipEntry(file.ClientName));

                return zipS;
            }
            catch
            {
                if (zipS != null)
                    zipS.Dispose();
                if (fileS != null)
                    fileS.Dispose();

                throw;
            }
        }
        public override Stream GetInputStream(UploadedFile file)
        {
            FileStream fileS = null;
            ZipInputStream zipS = null;

            try
            {
                string path = GetZipPath(file);

                fileS = File.OpenRead(path);
                zipS = new ZipInputStream(fileS);

                zipS.GetNextEntry();

                return zipS;
            }
            catch
            {
                if (fileS != null)
                    fileS.Close();

                if (zipS != null)
                    zipS.Close();

                return null;
            }
        }
Example #4
0
        public static void Log(UploadedFile file, string uploadId)
        {
#if DEBUG
            Log(" - Client FileName:" + file.ClientName);

            //if (file.Location is FileUploadLocation)
            //    Log(" - Server FileName:" + ((FileUploadLocation)file.Location).FileName);
#endif
        }
    /// <Summary>Save file</Summary>
    public override Stream GetWriteStream(UploadedFile file)
    {
      //
      //  Not working... file.ServerLocation is empty, however, the HttpRequest has the file contents
      //
      //
      //
      //
      //
      //




      var longLength = file.ContentLength;
      var contentLength = longLength > Int32.MaxValue ? 0 : (int)longLength;

      var buffer = new byte[contentLength];
      var start = 0;
      using (var fileStream = File.OpenRead(file.ServerLocation))
      {
        int count;
        while ((count = fileStream.Read(buffer, start, contentLength - start)) > 0)
        {
          start += count;
        }
      }

      var record = new ImportFile
                     {
                       Contents = buffer,
                       FileSize = contentLength,
                       OriginalFileName = file.ClientName,
                       UploadTime = DateTime.Now,
                       ProcessingStatus = "Imported"
                     };

      Db.ImportFiles.Add(record);
      Db.SaveChanges();

      return null;
    }
Example #6
0
        public static DocumentObject Build(UploadedFile fileData,
            string spaceId,
            string spaceSeqNo,
            string spaceName,
            string userId,
            string userName,
            string depId,
            Visible visible)
        {
            var fileName = fileData.ClientName;

            _logger.Debug("存储原始文件...");

            Guid fileId = Guid.NewGuid();
            _logger.Debug("存储原始文件完成");
            var document = new DocumentObject
            {
                Id = fileId,
                FileName = fileName,
                StorePath = fileData.ServerLocation,
                FileSize = fileData.ContentLength,
                CreateTime = DateTime.Now,
                DocumentType = fileName.ToDocumentType(),
                UpdateTime = DateTime.Now,
                CreateUserId = userId,
                CreateUserName = userName,
                SpaceId = spaceId,
                SpaceSeqNo = spaceSeqNo,
                SpaceName = spaceName,
                UpdateUserId = userId,
                UpdateUserName = userName,
                IsConvert = false,
                Visible = (int)visible,
                DepId = depId,
            };

            document.DisplayPath = DocumentSettings.GetDisplayUrl(Path.GetFileName(document.ConvertPath));

            return document;
        }
        public override Stream GetWriteStream(UploadedFile file)
        {
            Stream s = null;

            try
            {
                string fileName = GetStorePath(file.ClientName);
                file.ServerLocation = fileName;
                //mongoPolicy.AddStream(file.ServerLocation, file.ContentType, file.ServerLocation);
                s = MongoPolicy.OpenStream(fileName, file.ContentType);
                return s;

            }
            catch (Exception e)
            {
                if (s != null)
                {
                    CloseWriteStream(file, s, false);
                    RemoveOutput(file);
                }
                throw;
            }
        }
        public override Stream GetReadStream(UploadedFile file)
        {
            FileStream fileS = null;
            ZipInputStream zipS = null;

            try
            {
                fileS = File.OpenRead(file.ServerLocation);
                zipS = new ZipInputStream(fileS);

                zipS.GetNextEntry();

                return zipS;
            }
            catch
            {
                if (zipS != null)
                    zipS.Dispose();
                if (fileS != null)
                    fileS.Dispose();

                throw;
            } 
        }
        /// <summary>
        /// Inserts the record for the given file, and returns the id of the record inserted.
        /// </summary>
        /// <remarks>This is a very verbose implementation, because it supports every possible data type and doesn't use an ORM. When implementing in your solution,
        /// we recommend you rewrite using whatever data access layer you use.</remarks>
        public override string InsertRecord(UploadedFile file, IDbConnection cn, IDbTransaction t)
        {
            string category = file.UploadRequest.Data["fileCategory"];

            using (SqlCommand cmd = (SqlCommand)cn.CreateCommand())
            {
                StringBuilder insertCommand = new StringBuilder();

                insertCommand.Append("INSERT INTO ");
                insertCommand.Append(Table);
                insertCommand.Append(" (");
                insertCommand.Append(DataField);

                if (FileNameField != null)
                {
                    insertCommand.Append(",");
                    insertCommand.Append(FileNameField);
                }

                insertCommand.Append(",");
                insertCommand.Append("Category");

                if (DataType != SqlColumnDataType.FileStream)
                {
                    insertCommand.Append(") VALUES (NULL");
                }
                else
                {
                    insertCommand.Append(") OUTPUT INSERTED." + KeyField);
                    insertCommand.Append(" VALUES (CAST('' AS varbinary(MAX))");
                }

                if (FileNameField != null)
                {
                    insertCommand.Append(",@fileName");

                    SqlParameter fileNameParm = cmd.CreateParameter();

                    fileNameParm.ParameterName = "@fileName";
                    fileNameParm.DbType = DbType.String;
                    fileNameParm.Value = file.ClientName;

                    cmd.Parameters.Add(fileNameParm);
                }

                insertCommand.Append(",@category");

                SqlParameter categoryParm = cmd.CreateParameter();

                categoryParm.ParameterName = "@category";
                categoryParm.DbType = DbType.String;
                categoryParm.Value = category;

                cmd.Parameters.Add(categoryParm);

                insertCommand.Append(");");

                if (DataType != SqlColumnDataType.FileStream)
                    insertCommand.Append("SELECT SCOPE_IDENTITY();");

                cmd.CommandText = insertCommand.ToString();
                cmd.Transaction = t as SqlTransaction;

                try
                {
                    if (cn.State != ConnectionState.Open)
                        cn.Open();

                    return cmd.ExecuteScalar().ToString();
                }
                finally
                {
                    if (t == null)
                        cn.Close();
                }
            }
        }
        public override string GetServerFileName(UploadedFile file)
        {
            string fileRoot = file.UploadRequest.Data["fileRoot"];

            return fileRoot + "\\" + GetValidFileName(file.ClientName);
        }
 /// <Summary>Read file</Summary>
 public override Stream GetReadStream(UploadedFile file)
 {
   throw new NotImplementedException();
 }
 public override void RemoveOutput(UploadedFile file)
 {
   throw new NotImplementedException();
 }
        public override void RemoveOutput(UploadedFile file)
        {
            string path = GetZipPath(file);

            if (File.Exists(path))
                File.Delete(path);
        }
        string GetZipPath(UploadedFile file)
        {
            string location = SlickUploadConfiguration.UploadStreamProvider["location"];

            if (location == null || location.Length == 0)
                location = "~/Files/";

            return Path.Combine(HttpContext.Current.Server.MapPath(location), Path.GetFileNameWithoutExtension(file.ClientName) + ".zip");
        }
 public string GenerateFileName(UploadedFile file)
 {
     return Path.Combine(file.ClientName.Substring(0, 1), file.ClientName);
 }
 public override void RemoveOutput(UploadedFile file)
 {
     //MongoPolicy.Delete(file.ServerLocation);
     // If it's a valid upload
     if (!string.IsNullOrEmpty(file.ServerLocation) && MongoPolicy.Exist(file.ServerLocation))
     {
         MongoPolicy.Delete(file.ServerLocation);
     }
 }
 public override void RemoveOutput(UploadedFile file)
 {
     if (File.Exists(file.ServerLocation))
         File.Delete(file.ServerLocation);
 }
 public override Stream GetReadStream(UploadedFile file)
 {
     //mongoPolicy.GetBytes(file.ServerLocation);
     throw new NotImplementedException();
 }