/// <summary> /// Get the friendly name of the component. /// </summary> /// <param name="entityTypeObject">The entity type object whose name we want.</param> /// <returns>A string representing the name of the component.</returns> protected string GetComponentName(object entityTypeObject) { var entityType = entityTypeObject as Rock.Model.EntityType; if (entityType != null) { string name = FileFormatTypeContainer.GetComponentName(entityType.Name); if (!string.IsNullOrWhiteSpace(name)) { return(name.SplitCase()); } } return(string.Empty); }
protected void lbExport_Click(object sender, EventArgs e) { using (var rockContext = new RockContext()) { var batchId = tbBatchId.Text.AsInteger(); var batches = new FinancialBatchService(rockContext).Queryable().Where(b => b.Id == batchId).ToList(); var fileFormat = new ImageCashLetterFileFormatService(rockContext).Get(ddlFileFormat.SelectedValue.AsInteger()); var component = FileFormatTypeContainer.GetComponent(fileFormat.EntityType.Name); List <string> errorMessages; fileFormat.LoadAttributes(rockContext); var mergeFields = new Dictionary <string, object> { { "FileFormat", fileFormat } }; var filename = fileFormat.FileNameTemplate.ResolveMergeFields(mergeFields); var stream = component.ExportBatches(fileFormat, batches, out errorMessages); var binaryFileService = new BinaryFileService(rockContext); var binaryFileTypeService = new BinaryFileTypeService(rockContext); var binaryFile = new BinaryFile { BinaryFileTypeId = binaryFileTypeService.Get(Rock.SystemGuid.BinaryFiletype.DEFAULT.AsGuid()).Id, IsTemporary = true, FileName = filename, MimeType = "octet/stream", ContentStream = stream }; binaryFileService.Add(binaryFile); rockContext.SaveChanges(); pnlSuccess.Visible = true; hlDownload.NavigateUrl = ResolveUrl(string.Format("~/GetFile.ashx?Id={0}&attachment=True", binaryFile.Id)); } }