Web File Download (UI) |
This document present two different download file methods:
This example added a data item toolbar button with a download icon.
Declaration Toolbar Item and Action text Download
/// <summary> /// Toolbar Item Button on view Index (Download) /// </summary> private string ToolbarItemButtonIndexDownload = "Download";
Override method IndexGetToolbarItem and add Toolbar Button Download by data item
/// <summary> /// Add Toolbar Item Button Download /// </summary> protected override List<ToolbarButton> IndexGetToolbarItem() { var lToolbar = base.IndexGetToolbarItem(); lToolbar.Add(new SOWIWeb.Helper.ToolbarButton(SOWIWeb.Helper.ButtonType.Action) { Icon = "glyphicon glyphicon-cloud-download", MVCController = "TemplateFile", MVCAction = ToolbarItemButtonIndexDownload, TooltipText = this.DictionaryUI.ToTranslate(SOWIData.Management.DictionaryUIGroup.Button.ToString(), ToolbarItemButtonIndexDownload) }); return lToolbar; }
Add method File Result Download
#region --- Download --- /// <summary> /// Gives file content /// </summary> public FileResult Download() { var lItem = SOWIApp.Package.TemplateFile.GetFileContent(this.ID, this.AppTemplateFile.ConnectionString, this.AppTemplateFile.UserName, this.AppTemplateFile.ClientID); string lFileName = lItem.Name; string lType = lItem.Type; byte[] lContent = lItem.Content; if (lType.Length == 0) { string lFileExtension = System.IO.Path.GetExtension(lFileName); lType = SIC.File.MIME.GetMIMEType(lFileExtension); } return File(lContent, lType, lFileName); } #endregion
This example added a toolbar button with a export icon.
... TODO: create a example based at view Details ...
Declaration Toolbar Buttons include Submit button Export
private List<SOWIWeb.Helper.ToolbarButton> ObjektGetToolbar() { var lToolbar = new List<SOWIWeb.Helper.ToolbarButton>(); // other toolbar buttons lToolbar.Add(new SOWIWeb.Helper.ToolbarButton(SOWIWeb.Helper.ButtonType.Submit) { SubmitValue = easyPlanHelper.ToolbarButtonsObjekt.Export.ToString(), Icon = "glyphicon glyphicon-export", Label = "Export" }); return lToolbar; }
...post ...
[HttpPost] public ActionResult Details(string submit, DataClassItem pItem) { if(submit == "Export") { } }
private ActionResult ObjektOnActionResultPostExport(DataItemClass pItem) { AppEasyPlan.Export(pItem); SOWIWeb.Helper.Session.DownloadFileName = AppEasyPlan.ExportFileName; SOWIWeb.Helper.Session.DownloadContent = AppEasyPlan.ExportContent; pItem.Download = true; SOWIWeb.Helper.Session.Message = "easyPlan Objekt wird erstellt!"; return ObjektOnActionResultPostSave(pItem); }