How To: Upload a File to a SharePoint Library with the File Attachment Control

In this article you use the File Attachment control in a SmartForm to upload a file to a SharePoint library. You configure a rule on a button with the Upload Document method of the library's SmartObject.

Scenario

Your company creates sales summary documents in Microsoft Word and uses a SharePoint library to store them. You use a SmartForm view to upload the documents to a SharePoint library.

Steps

In this scenario, you create a view and add the File Attachment and Button controls. You configure the button rule with the Upload Document SmartObject method to upload the file to your SharePoint library. After testing the view you add it to a form.

Setup Steps

The following steps set up the scenario. If you want to skip the setup steps and view the topic step, go to Create a new view using your SharePoint library SmartObject.

  1. Create your SharePoint document library. In this scenario the document library is called SalesDocuments.
  2. Appify your document library. This creates the K2 SmartObjects needed to upload the file. See Creating an Application Through a List or Library for the steps to appify your library.

Create a view to use a File Attachment control and Button control

Create and configure a view using a File Attachment control. Add a Button control and configure the button clicked event to upload the file to the SharePoint library.

  1. Create a new view using your SharePoint library SmartObject.
    1. Create a new view in K2 Designer. Select the View option and click Create.
    2. Name the view UploadToLibary_View. Enter your description.
    3. Select a Category for the view. In this example the Denallix category is used.
    4. Select Item View as the View Type.
    5. For the Data Source select your SharePoint library SmartObject. In this scenario the SharePoint 2013 > portal.denallix.com > Libraries > SalesDocuments > SalesDocuments SmartObject is used. Adding the SmartObject as the Data Source for this view adds the context of the SharePoint library, which you use in later steps.
    6. Click Create to create the view.

  2. Configure your view to use the File Attachment control. Use a Label with the File Attachment control to make it easier to locate on your view.
    1. Select Create Layout Table Only.

    2. Configure your view table to have two rows and two columns. Click OK to continue.
    3. Select the Toolbox tab.
    4. Drag and drop a Label control into the first cell.
    5. In the label Properties tab change the Name property to File Attachment Label.
    6. Specify Document as the Text property.
    7. From the Toolbox tab, drag and drop a File Attachment control to the second cell.
  3. Add a Button control to your view and configure the button clicked Rule to use the Upload Document SmartObject of your SharePoint library.
    1. Drag and drop a Button control from the Action section of the Toolbox to the bottom right cell.
    2. In the button Properties tab change the Name to Upload Button.
    3. Specify Upload as the Text property.

    4. Select the bottom right cell and set the cell formatting to align from right.

    5. Select the Upload button and then click the Rules tab.
    6. Select the When Upload Button is Clicked rule and click Edit Rule.
    7. Select the Actions tab and click Execute a SmartObject Method.
    8. In the new rule then section click select method.
    9. Select your SharePoint library's SmartObject. In this scenario is SharePoint 2013 > portal.denallix.com > Libraries > SalesDocuments > SalesDocuments.
    10. Click OK.
    11. Click select method and select the Upload Document method.
    12. Click configure.
    13. In the Context Browser expand the SalesUpload_View > SalesDocuments SmartObject.
    14. Scroll down and drag and drop Source Site URL to the Site URL parameter.
    15. Drag and drop Source Library to the List ID parameter.
    16. Expand the SalesUpload_View Controls.
    17. Drag and drop the File Attachment control to the Document input property.
    18. Click Finish to complete this rule.
    19. Click OK to save the rule modification.
    20. Click Finish to save your view.
  4. Test your view.
    1. On the UploadToLibrary_View page in K2 Designer, click Run.

    2. Click the Click here to attach a file file attachment area.
    3. Navigate to and select your document.
    4. Click Open.
    5. Wait for your file to upload.

    6. Click the Upload button.
    7. Go to your SharePoint library and see that the document is uploaded.
    8. Your view is now ready to be used in a form. If you are not familiar with creating forms, see How To: Create a Form.
Review

You used a File Attachment control along with a button and rule to upload a file from a view to a SharePoint library.