Developer Guide
aspx:FieldFileUpload

    This is a component that creates an input field to upload a file.

     <aspx:FieldFileUpload id='myFile' allowMultiple='false' runat='server'/>


    When using this component, you can read the uploaded file information by binding the ID of the component to your controller's action parameter.

    [HttpPost]
    public ActionResponse SaveFile(HttpPostedFile myFile){...}

     

    Reading uploaded file contents

    The FileBytes method returns the file converted into an array of bytes, which can then be used for conversion.

    [HttpPost]
    public ActionResponse SaveFile(HttpPostedFile myFile)
    {
       // convert myFile's bytes to Base64
       string content = Convert.ToBase64String(myFile.FileBytes());
    }

     

    Creating a Document from the uploaded file

    In order to save the uploaded file as a Document within the Magentrix platform, use the Document "Load" method.

    [HttpPost]
    public ActionResponse SaveFile(HttpPostedFile myFile)
    {
       // load the uploaded file as Document
       var newDoc = Document.Load(myFile);
    
       //assign the new Document to a folder.
       newDoc.FolderId = "7Os0000000000200001";
    
       try
       {
          Create(newDoc);
       }
       catch(DatabaseException ex)
       {
          AspxPage.AddError(ex);
          return View();
       }
       
       //successfull
       AspxPage.AddMessage("Uploaded file is successfully saved.");
       return View();
    }

     

    Creating New Magentrix Attachments From File Uploads

    You can also easily create new Magentrix Attachments with files uploaded, see the below article to learn more about creating Magentrix Attachments:

    Creating Magentrix Notes and Attachments Programmatically 

     

    Handle multiple file uploads

    If the user needs to upload multiple files within your page, you can access the uploaded documents without adding them one by one to the Action's arguments as seen below.

    [HttpPost]
    public ActionResponse SaveFiles()
    {
        for(int i=0;i< Request.Files.Count;i++)
        {
             HttpPostedFile uploadedFile = Request.Files[i];
             if (uploadedFile.ContentLength == 0) continue;
    
             //save the file and move on to the next.
             //ensure the uploadedFile is not null, since user may not have uploaded any files.
        }
    
        return View();
    }