Save MS Forms Attachment to SharePoint Library

by

In this article, we will use Microsoft Forms as the user interface for students to upload their homework. Then, Power Automate Cloud will save their files to a SharePoint library, organized by their first and last names.

Create Microsoft Forms

First, we will create a Microsoft Form with two questions:

  • Name-Surname to create the folder in SharePoint
  • Upload your file to create the file in the SharePoint library
  1. Go to https://forms.office.com/ and press “New Form” button
Press “New Form” button

2. Name the form, for example, ‘Homework JPN101’, then press the ‘Text’ button to select the question type as ‘Text’

Neme the form and select the first question type as “Text”

3. Type ‘Name-Surname’ in the question field, then toggle on the ‘Required’ option as shown in the image below

Create the first question

4. Select ‘Upload File’ as the question type.

Select the second question type as “Upload File”

5. Type ‘Upload your file’ in the question field, then select file number limit as 1 and toggle on the ‘Required’ option as shown in the image below

Create the second question

Click preview button, the Form will shown as per below image

Complete Microsoft Forms

Create SharePoint Library

Go to the SharePoint site where you want to collect the files, then create a SharePoint library.

In my case, I will use the existing SharePoint site named ‘Power Automate PenBot’. Press ‘New’ and select ‘Document library’.

New > Document Library

Then, select “Blank Library” and name the SharePoint Library name such as “Homework JPN101”

Select Blank Library
Name the SharePoint Library
SharePoint Library “Homework JPN101”

Create Flow

Go to https://make.powerautomate.com/

Press “Create” tab, select “Automated cloud flow”

Create > Automate cloud flow

Name the flow, for example, “Upload Homework JPN101”, select trigger “When a new response is submitted”, and press “Create” button

Name the flow, select trigger, and press create

Select Form Id, and press “New Step”

Select “Get response details” action, select Form Id, add dynamic content Response Id and press “New Step”

Dynamic content “Response Id” from trigger “When a new response is submitted”

Select “Initialize variable” action, name the variable, select variable type, add dynamic content as per below image and press “New Step”

The purpose of this action is to check for an existing folder name in the SharePoint library

Dynamic content “Name-Surname” from “Get response details”

Select the ‘Get items’ action

  • Choose your SharePoint site
  • Type your SharePoint library name in the ‘List Name’ field (every SharePoint library is essentially a list, so you can enter the library name here)
  • Enter the Filter Query as shown in the image below. For more details, you can watch this video by Mr. Alireza
  • Press “New Step”
Dynamic content “Name-Surname” from “Get response details”

Noted: Normally, the “content type” column is hidden when we create a SharePoint library.

You can show it by left click at “Add column” and go to “Show or hide column”

The “name” column, actual name is “FileLeafRef”

“Name” colum Internal name is “FileLeafRef” check from SharePoint Client Browser (SPCB)

Select the “Condition” action, enter the condition as expression lenght() and select dynamic content “value” from Get items”, choose “is equal to”, and type the value 1. (Folder of that user already exist in SharePoint library)

Write expression length() and select Dynamic content “value” from “Get items”

The code of condition will be like this:

length(outputs('Get_items')?['body/value'])

Then, add an “Apply to each” action under the “If yes” branch and do following steps:

  • write expression json()
  • select dynamic content “Upload your file” from Get response details”
  • press “Add an action” in apply to each
Write expression json() and select Dynamic content “Upload your file” from “Get response details”

The code of apply to each will be like this:

json(outputs('Get_response_details')?['body/rd2f5334812b240c891fe49e79f108dad'])

Add “Get file content (OneDrive)” and type expression as per below code block, press “OK” button, and press “Add an action” in apply to each

We use OneDrive connector because the attachment from Microsoft Forms will store in the OneDrive

item()?['id']
Write expression item()?[‘id’]

These steps mean that for each response detail from MS Forms, you will retrieve the file content of each id.

Add “Create File (SharePoint)”

  • Choose your SharePoint site
  • Select your folder and type / and select dynamic content “folderName” from “Initialize Variable” step
  • Write expression in File Name as item()?[‘name’]
  • Select dynamic content “File content” from “Get file content”
item()?['name']

Add action under the “If no” branch (Folder of that user not exist in SharePoint library)

Add “Create new folder”

  • Choose your SharePoint site
  • Select SharePoint Library
  • Add dynamic content “folderName” from “Initialize Variable” step

Copy “Apply to each” from “If yes” branch

Then add action under the “If no” branch

Select “My Clipboard”, select “Apply to each”

The completed flow will look like this:

Test

Submit Form

Check SharePoint Library

Create New Folder
Add attachment in folder

Submit another form with the same name as the previous one

Add attachment in folder

Did You Enjoy this Article?

Subscription to get new articles sent to your inbox each week for FREE

Question?

If you have any questions or feedback about this article please leave a message in the comments section below.


Comments

Leave a comment

Subscribe to get new articles sent to your inbox each week for FREE