How to Multiple Folder and File Upload Document in Sharepoint Document Library Programmatically
Uploading files to SharePoint document library from Power Apps merely got easier! Attaching files in Power Apps and saving to them SharePoint is a common requirement for many apps so its an important skill to learn. To do this we will apply the new Power Apps (V2) trigger in Power Automate which includes the file data type as an input It is no longer necessary to perform a complicated series of steps to transform a file to binary using the JSON role and then back to Base64 (not exactly low-lawmaking).
In this article I will show you the easiest way to upload files to a SharePoint certificate library in Power Apps and add together metadata (i.e. tags) to the file.
Tabular array of Contents: Introduction: The Submit A Contract App Setup The SharePoint Document Library Insert An Attachments Field Make A Menstruum To Upload Documents To A SharePoint Library Connect The 'Upload To SharePoint' Catamenia In Power Apps Upload Multiple Files To A SharePoint Document Library Add Metadata To A SharePoint Document Library Brandish Recently Uploaded Files
Introduction: The Submit A Contract App
The Submit A Contract app is used by salespeople at a bakery to upload contract files to a SharePoint certificate library. One time a contract is signed the salesperson attaches the file, adds some metadata (customer proper noun, contract engagement and client blazon) to help continue the contracts organized and presses the upload button to submit the file
Setup The SharePoint Document Library
Add a new SharePoint certificate library called Contracts with the post-obit columns and types:
- Name (single-line text)
- CustomerName (single-line text)
- SoldDate (Engagement only)
- Industry (unmarried-line text)
The certificate library will await similar this one time nosotros upload some files later in the tutorial.
Insert An Attachments Field
In the Submit A Contract app a salesperson needs to add together a file to an attachments field and upload it to SharePoint. Open up Ability Apps and Create a new app from bare. And so insert a few labels and icons to get in await like the screenshot beneath.
The attachments field cannot be inserted from the card then we must use a workaround. Become to the data tab on the left menu and add any existing SharePoint listing from your SharePoint site. Practise non add the Contracts SharePoint document library nosotros created earlier. Nosotros cannot utilize it to generate an attachments field.
Create a new Edit Class with your SharePoint list as the data source. The attachments command should automatically announced when nosotros create the class. If it does non, y'all can add the attachments field using Edit fields on the right-side menu.
Cut the attachments control and paste it outside the course. Delete the form.
Use the following properties in the attachments control:
Items: Blank() DisplayMode: DisplayMode.Edit MaxAttachments: 1
Our app now has an attachments field we tin can use to upload the contract documents. We can now delete connection to the SharePoint list. It is no longer needed.
Make A Flow To Upload Documents To A SharePoint Library
Documents cannot be uploaded to a SharePoint document library direct from Ability Apps. Nosotros will demand to create a Power Automate flow to do it instead. Open up the Power Automate action from the meridian menu and select Create a new flow.
Choose the Ability Apps button template.
Name the menstruum UploadFileToDocument library and click Save.
We want to use the PowerApps (V2) trigger because it supports files every bit an input blazon whereas the PowerApps trigger does non. Delete the PowerApps trigger and add PowerApps(V2) in its place.
Select the File input type. Proper noun the input File Content. Make File Content a required input.
Add a SharePoint action to the flow: Create File. Use your SharePoint site address and document library folder path as inputs. The File Content field should reference the file found in our menses trigger.
File Name requires a flow expression. Open the period expression editor then copy + paste this lawmaking into the File Name field.
triggerBody()['file']['name']
We are at present done creating the catamenia to upload a certificate.
Connect The 'Upload To SharePoint' Catamenia In Power Apps
Go back to PowerApps and add a push. Select the OnSelect property and click on the UploadFileToDocumentLibrary field in the Ability Automate card.
The flow will announced as a connection in the data tab.
Remove whatever code from the Upload button'southward OnSelect property and supersede information technology with this code. A file must be passed every bit an object to Power Automate. The contentBytes field holds a reference to the zipper file and proper noun stores the filename and extension.
UploadFileToDocumentLibrary.Run( { contentBytes: First(att_SubmitContract_AttachFile.Attachments).Value, name: First(att_SubmitContract_AttachFile.Attachments).Name } );
Notation: if you are receiving an error when passing the file to the flow brand certain you have ready the flow input to be a required field.
Nosotros're done creating the 'upload a document to a SharePoint library' functionality. Exam your app to make certain its working.
The contract document should announced in your SharePoint site as shown below.
Upload Multiple Files To A SharePoint Document Library (Optional)
If we wanted to include the ability to upload multiple files at the same fourth dimension we could change the OnSelect property of the upload button to loop through each attachment and run the flow once per file. We will too need to increase the MaxAttachments belongings of the zipper control from ane to another value.
ForAll( att_DocLib_SubmitContract.Attachments Every bit Document, UploadFileToDocumentLibrary.Run( { contentBytes: Document.Value, name: Document.Name } ) );
Since this is an optional step, the rest of this commodity will assume yous have used the unmarried-file upload method.
Add Metadata To A SharePoint Document Library
The salesperson must also include additional data about the contract to keep the contracts files organized. The technical term for this is metadata: "information-well-nigh-data". Merely most folks only call information technology tagging documents.
Add a few text inputs (Customer Name, Manufacture) and a engagement picker (Contract Date) equally shown below to capture the metadata.
We must update the Upload Document To A SharePoint Library period to insert the metadata from Ability Apps. Change the Power Apps (V2) trigger activity to add 3 new inputs as shown below. They should all be required inputs.
Then add together another action at the bottom of the flow: SharePoint – Update file properties
Now we are done updating the Flow. Go back to Power Apps…
…and update the OnSelect property of the upload push with this additional code to pass the new parameters. Notice that the parameter names practice not match the names we divers in flow. They are generic names based on the data type.
UploadFileToDocumentLibrary.Run( { contentBytes: First(att_SubmitContract_AttachFile.Attachments).Value, name: Start(att_SubmitContract_AttachFile.Attachments).Proper name }, txt_SubmitContract_CustName.Text, Text( dte_SubmitContract_ContractDate.SelectedDate, "[$-en-U.s.a.]yyyy-mm-dd" ), txt_SubmitContract_ClientType.Text );
Nosotros can at present include metadata with the certificate at the time of upload to SharePoint. Give this new functionality a test and check SharePoint to make certain the data was successfully written.
Display Recently Uploaded Files
A salesperson might want to see a list of the most recently uploaded files. To add this feature, connect the app to the Contract document library in SharePoint.
Then add a gallery to the Submit A Contract app that looks like the screenshot beneath.
Use this code in the Items holding of the the gallery to show uploads from newest-to-oldest.
Sort('Contracts', Modified, Descending)
Put this code in the Text property of the name characterization…
ThisItem.Name
…and this code in the Text holding of the engagement modified characterization.
ThisItem.Modified
That's information technology, we're done!
Did You Enjoy This Article? 😺
Subscribe to go new Power Apps articles sent to your inbox each week for Costless
Questions?
If yous have any questions or feedback about Power Apps Easiest Way To Upload Files To A SharePoint Document Library please leave a bulletin in the comments section below. You can post using your email address and are not required to create an business relationship to join the give-and-take.
Source: https://www.matthewdevaney.com/power-apps-easiest-way-to-upload-files-to-a-sharepoint-document-library/
0 Response to "How to Multiple Folder and File Upload Document in Sharepoint Document Library Programmatically"
Post a Comment