/// <summary> /// Call this during ModifyData. This returns the file collection ID of the existing or just-inserted file collection. /// This will return an ID even if there are 0 files in the collection (in other words, no file). No file should always be /// represented by a non-null file collection ID which happens to have 0 files in it. Null file collection IDs are not supported. /// </summary> public int ModifyData() { if (fileCollectionId == null) { fileCollectionId = BlobFileOps.SystemProvider.InsertFileCollection(); } var rsFile = uploadedFile.GetPostBackValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues); if (rsFile != null) { BlobFileOps.SystemProvider.DeleteFilesLinkedToFileCollection(fileCollectionId.Value); BlobFileOps.SystemProvider.InsertFile(fileCollectionId.Value, rsFile.FileName, rsFile.Contents, BlobFileOps.GetContentTypeForPostedFile(rsFile)); } return(fileCollectionId.Value); }
private ControlList getUploadControlList() { var dm = PostBack.CreateFull(id: PostBack.GetCompositeId(postBackIdBase, "add")); RsFile file = null; var fi = FormItem.Create( "", new EwfFileUpload(), validationGetter: control => new EwfValidation( (pbv, validator) => { BlobFileOps.ValidateUploadedFile(validator, control, acceptableFileExtensions, ValidateImage, AcceptOnlyImages); file = control.GetPostBackValue(pbv); }, dm)); dm.AddModificationMethod( () => { if (file == null) { return; } var existingFile = files.SingleOrDefault(i => i.FileName == file.FileName); int newFileId; if (existingFile != null) { BlobFileOps.SystemProvider.UpdateFile(existingFile.FileId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file)); newFileId = existingFile.FileId; } else { newFileId = BlobFileOps.SystemProvider.InsertFile(fileCollectionId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile(file)); } if (NewFileNotificationMethod != null) { NewFileNotificationMethod(newFileId); } EwfPage.AddStatusMessage(StatusMessageType.Info, "File uploaded successfully."); }); return(ControlList.CreateWithControls( true, "Select and upload a new file:", fi.ToControl(), new PostBackButton(dm, new ButtonActionControlStyle("Upload new file"), false))); }