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. Create an application with Data (artifacts) for your document library. This creates the SmartObjects needed to upload the file. See Creating an Application Through a List or Library for the steps to create artifacts for 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 the 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 we created a new category called Sales.
    4. Select Item View as the View Type.
    5. For the Data Source select your SharePoint library SmartObject. In this scenario the 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 right.

    5. Select the Upload button and then click the Rules tab.
    6. Click Add Rule.
    7. Select the Actions tab and click Execute a SmartObject Method.
    8. Click select SmartObject and then select your SharePoint library's SmartObject. In this scenario it is SalesDocuments.
    9. Click OK.
    10. Click select method and select the Upload Document method.
    11. Click configure.
    12. In the Context Browser expand the UploadToLibrary_View > SalesDocuments SmartObject.
    13. Scroll down and drag and drop Source Site URL to the Site URL parameter.
    14. Drag and drop Source Library to the List ID parameter.
    15. Expand the UploadToLibrary_View > Controls.
    16. Drag and drop the File Attachment control to the Document input property.
    17. Click Finish and OK to save the rule.
    18. Click Finish to save and exit the view.
  4. Test your view.
    1. In the Designer, click Run to run your view.

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

    6. Go to your SharePoint library and see that the document is uploaded.
    7. 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.