Click or drag to resize

Web File Download (UI)

This document present two different download file methods:

1. Example: File Download with MVC Action

This example added a data item toolbar button with a download icon.

Data Item Toolbar Standard Add Download

To do: Web Controller

  1. Declaration Toolbar Item and Action text Download

    C#
    /// <summary>
    /// Toolbar Item Button on view Index (Download)
    /// </summary>
    private string ToolbarItemButtonIndexDownload = "Download";
  2. Override method IndexGetToolbarItem and add Toolbar Button Download by data item

    C#
    /// <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;
    }
  3. Add method File Result Download

    C#
    #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
2. Example: File Download with MVC Submit

This example added a toolbar button with a export icon.

... TODO: create a example based at view Details ...

To do: Web Controller

  1. Declaration Toolbar Buttons include Submit button Export

    C#
    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;
    }
  2. ...post ...

    C#
    [HttpPost]
    public ActionResult Details(string submit, DataClassItem pItem)
    {
      if(submit == "Export")
      {
      }
    }

    C#
    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);
    }