void ListViewAlbums_ItemInserting(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e) { Album album = new Album(); UpdateAlbum(e, album); context.Albums.InsertOnSubmit(album); RadAsyncUpload uploadAllImages = (e.ListViewItem.FindControl("RadAsyncUpload2") as RadAsyncUpload); if (uploadAllImages.UploadedFiles.Count > 0) { UploadedFile zipFile = uploadAllImages.UploadedFiles[0]; using (ZipPackage zipPackage = ZipPackage.Open(zipFile.InputStream, FileAccess.Read)) { List <ZipPackageEntry> allEntries = zipPackage.ZipPackageEntries.ToList(); foreach (ZipPackageEntry entry in allEntries) { byte[] imageData = new byte[entry.UncompressedSize]; entry.OpenInputStream().Read(imageData, 0, entry.UncompressedSize); DataContext.Image image = new DataContext.Image(); image.AlbumID = album.ID; image.FileName = entry.FileNameInZip; image.Data = imageData; album.Images.Add(image); } } } context.SubmitChanges(); }
void ImagesListView_ItemCommand(object sender, RadListViewCommandEventArgs e) { if (e.CommandName == "DownloadAllAsZip") { RadListViewDataItem item = ListViewAlbums.SelectedItems[0]; int parentID = Convert.ToInt32(item.GetDataKeyValue("ID").ToString()); string albumName = item.GetDataKeyValue("Name").ToString(); List <DataContext.Image> allImagesFromAlbum = (from a in context.Images where a.AlbumID == parentID select a).ToList(); MemoryStream memStream = new MemoryStream(); Package = ZipPackage.Create(memStream); foreach (var image in allImagesFromAlbum) { Stream stream = new MemoryStream(image.Data); Package.AddStream(stream, image.FileName); } Package.Close(false); memStream.Position = 0; if (memStream != null && memStream.Length > 0) { Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + albumName + ".zip"); Response.ContentType = "application/zip"; Response.BinaryWrite(memStream.ToArray()); Response.End(); } } if (e.CommandName == "DownloadImage") { RadListViewDataItem item = e.ListViewItem as RadListViewDataItem; int imageID = Convert.ToInt32(item.GetDataKeyValue("ID").ToString()); DataContext.Image image = (from i in context.Images where i.ID == imageID select i).First(); byte[] data = image.Data; string name = image.FileName; if (data != null && data.Length > 0) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("content-disposition", "attachment; filename=" + name); Response.BinaryWrite(data); Response.End(); } } }
void ImagesListView_ItemDeleting(object sender, RadListViewCommandEventArgs e) { RadListViewDataItem deletedItem = e.ListViewItem as RadListViewDataItem; int imageId = Convert.ToInt32(deletedItem.GetDataKeyValue("ID").ToString()); DataContext.Image image = (from i in context.Images where i.ID == imageId select i).First(); context.Images.DeleteOnSubmit(image); context.SubmitChanges(); }
void ImagesListView_ItemUpdating(object sender, RadListViewCommandEventArgs e) { var dataItem = e.ListViewItem as RadListViewDataItem; int imageId = Convert.ToInt32(dataItem.GetDataKeyValue("ID").ToString()); DataContext.Image image = (from a in context.Images where a.ID == imageId select a).First(); RadAsyncUpload radUpload = (e.ListViewItem.FindControl("RadAsyncUpload1") as RadAsyncUpload); if (radUpload.UploadedFiles.Count > 0) { UploadedFile file = radUpload.UploadedFiles[0]; byte[] data = new byte[file.InputStream.Length]; file.InputStream.Read(data, 0, (int)file.InputStream.Length); image.Data = data; context.SubmitChanges(); } }
void ListViewAlbums_ItemInserting(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e) { Album album = new Album(); UpdateAlbum(e, album); context.Albums.InsertOnSubmit(album); RadAsyncUpload uploadAllImages = (e.ListViewItem.FindControl("RadAsyncUpload2") as RadAsyncUpload); if (uploadAllImages.UploadedFiles.Count > 0) { UploadedFile zipFile = uploadAllImages.UploadedFiles[0]; using (ZipPackage zipPackage = ZipPackage.Open(zipFile.InputStream, FileAccess.Read)) { List<ZipPackageEntry> allEntries = zipPackage.ZipPackageEntries.ToList(); foreach (ZipPackageEntry entry in allEntries) { byte[] imageData = new byte[entry.UncompressedSize]; entry.OpenInputStream().Read(imageData, 0, entry.UncompressedSize); DataContext.Image image = new DataContext.Image(); image.AlbumID = album.ID; image.FileName = entry.FileNameInZip; image.Data = imageData; album.Images.Add(image); } } } context.SubmitChanges(); }