Upload Files From Power apps to SharePoint Document Library

Loading

Requirement: Uploading the files to SharePoint Document Library from Power apps, Attaching files in power apps and store that files into our SharePoint Document Library.

Create a blank canvas app, In that insert a Edit Form and use SharePoint list as Data Source. When we create the form the attachments control should be automatically appear. If Incase it doesn’t, we can add the attachment field using edit fields on the right-side menu.

The attachment field can not be inserted from the menu so we must use a workaround. Go to the data tab on the left menu add the data source as SharePoint list. Create a Document Library we can not use it to generate an attachment field.

Make a Flow to Upload Documents to SharePoint Library:

Documents can not be Uploaded directly from Power apps to SharePoint Document Library. Through this flow we can store the uploaded files in Power apps into SharePoint Library.

Create a Instant flow in that select the power apps(V2). Add input type in that select Number type name the input as ParentID, and add one more input type in that select the File type name the input as File Content. Make ParentID and File Content is required input.

Next, Add SharePoint action to the flow. i.e., Create a file. Select SharePoint Site Address and select the Folder Path is your Document Library. First take File Content from power apps trigger and write below mentioned expression in File name.

triggerBody()['file']['name'].

Then add Update file Properties action in that give your SharePoint Site Address and select the Library Name, Add “ItemId” from the SharePoint in Id. After that take the ParentID from the trigger.

At last add Respond to a power apps or flow action then Save the flow.

Go to the Power apps and add flow to the button it will shows all the power apps related flows, Select the flow it shows Flow Dot Run.

Write below mentioned Code to the OnSelect property of the button.

Set(
    RecID,
    Patch(
        'Candidate Information',
        Defaults('Candidate Information'),
        {
            EmployerOrCompanyName: DataCardValue172_2.Text,
            StartDate: DataCardValue173_2.SelectedDate,
            EndDate: DataCardValue174_2.SelectedDate,
            CitY: DataCardValue175_2.Text,
            StatE: DataCardValue176_2.Text,
            CountrY: {Value: DataCardValue177_2.Selected.Value},
            Designation: DataCardValue178_2.Text,
            EmpID: DataCardValue179_2.Text,
            GrossAnnualIncomE: Value(DataCardValue180_2.Text),
            NatureOfEmployeement: {Value: DataCardValue181_2.Selected.Value},
            DoYouHavePF: DataCardValue182_2.Value,
            PFNumber: DataCardValue183_2.Text,
            DoYouHaveUAN: DataCardValue184_2.Value,
            UAN: Value(DataCardValue185_2.Text),
            DoYouHaveForm16: DataCardValue189_2.Value,
            Select: {Value: DataCardValue187_2.Selected.Value}
        }
    ).ID
);
ForAll(
    DataCardValue2.Attachments,
    WorkExperienceDocuments.Run(
        RecID,
        {
            file: {
                contentBytes: Value,
                name: Name
            }
        }
    )
);

Add Parameters to the flow and Save, when the user enter the details, drop the file in Attachment and Click on the Button the flow will trigger and the attachment should be store into the SharePoint Library.

Leave a Reply

Your email address will not be published. Required fields are marked *