Click or drag to resize

Web Controller to File Upload

This example present a implementation of SOWI Web Controller with method of a file upload and include his user interface (views)

This topic contains the following sections:

Overview
SOWIWeb Upload
Class Diagram

A project example

easy Plan Web Schacht Zeichnung
User Interface

Based on SOWI Web Foundation (see: SOWIWeb.Foundation)

View Create or Edit has the Upload icon

Screen Schacht Zeichnung Dialog Upload

HTML Dialog for choose an import or an upload file

Controller

Based on SOWI Web Controller standard (see: SOWIWeb.HelperControllerStandardDataItemClass and SOWIWeb.Helper.InterfaceIControllerStandard)

SOWI Web controller must parameter pCanUpload on (true) (see constructor ControllerStandardDataItemClassControllerStandardDataItemClass)

This example activate the upload icon so can click upload

C#
/// <summary>
/// Web controller
/// </summary>
public class SchachtZeichnungController : SOWIWeb.Helper.ControllerStandard<easyPlanData.SchachtZeichnung>
{
    /// <summary>
    /// Initializes a new instance of the SchachtZeichnungController class.
    /// Constructor without parameter. Sets the availability for uploading files.
    /// </summary>
    public SchachtZeichnungController() : base(pCanUpload: true) { }

    ...
}
App

Nothing needs to be done! When the following conditions are met.

Based on App standard and on based on Web standard controller then calls web controller method Upload and save file data to data item.

Standard App can implemented by SOWIApp.FoundationAppStandardDataItemClass or SOWIApp.FoundationIAppStandardDataItemClass

Standard Web controller can implemented by SOWIWeb.HelperControllerStandardDataItemClass or SOWIWeb.Helper.InterfaceIControllerStandard

Requirement: it must the same data item class be used in App module and in Web Controller.

Option: method Upload can be overwrite. See a example.

C#
/// <summary>
/// Puts Schachtzeichnung to data item
/// </summary>
/// <param name="pItem">Data item</param>
/// <param name="pFileContent">Schachtzeichnung</param>
public override void Upload(ref easyPlanData.SchachtZeichnung pItem, FileContent pFileContent)
{
    if (pFileContent.IsValid)
    {
        pItem.Name = pFileContent.Name;
        pItem.Type = pFileContent.Type;
        pItem.Content = pFileContent.Content;
    }
}
Data

Implement the interface IFileContent. This has the following fields: Name, Content and Type.

The example is based on SOWI Data Standard so only the two fields (Content and Type) have to be implemented.

C#
public class SchachtZeichnung : SOWIData.DataStandard, SOWIData.Helper.Interface.IFileContent
{
    ...

    //* field Name is in SOWIData.DataStandard *

    /// <summary>
    /// e.g. MIME content type
    /// </summary>
    public string Type { get; set; }

    /// <summary>
    /// File Content
    /// </summary>
    public byte[] Content { get; set; }

    ...

}
See Also