Ejemplo n.º 1
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            byte[] fileData = null;
            Stream fileStream = null;
            int length = 0;
            if (FileUploadControl.HasFile && FileUploadControl.PostedFiles.All(f => f.FileName.Substring(f.FileName.IndexOf('.') + 1).ToLower() == "zip"))
            {
                length = FileUploadControl.PostedFile.ContentLength;
                fileData = new byte[length + 1];
                fileStream = FileUploadControl.PostedFile.InputStream;
                fileStream.Read(fileData, 0, length);
            }
            else
            {
                Response.Write("Invalid File Format");
                return;
            }

            var memStream = new MemoryStream(fileData);
            var result = this.UnZipToMemory(memStream);
            var db = new FileUploadDbContext();

            foreach (var item in result)
            {
                var buffer = new byte[item.Value.Length + 1];
                item.Value.Read(buffer, 0, buffer.Length);
                var textFile = new FileModel();
                textFile.Content = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                textFile.Name = item.Key;
                db.Files.Add(textFile);
            }

            db.SaveChanges();
            this.FilesRepeater.DataBind();
        }
Ejemplo n.º 2
0
 public IEnumerable<FileModel> FilesRepeater_GetData()
 {
     var db = new FileUploadDbContext();
     return db.Files.ToList();
 }