Skip to content Skip to sidebar Skip to footer

Windows App to Upload Documents to Sharepoint

Uploading files to SharePoint document library from Ability Apps just got easier! Attaching files in Ability Apps and saving to them SharePoint is a mutual requirement for many apps so its an of import skill to learn. To do this nosotros will utilize the new Power Apps (V2) trigger in Power Automate which includes the file data type every bit an input It is no longer necessary to perform a complicated series of steps to transform a file to binary using the JSON function and and then back to Base64 (non exactly depression-code).

In this article I will show you the easiest manner to upload files to a SharePoint document library in Power Apps and add metadata (i.e. tags) to the file.

          Table of Contents: Introduction: The Submit A Contract App Setup The SharePoint Document Library Insert An Attachments Field Brand A Flow To Upload Documents To A SharePoint Library Connect The 'Upload To SharePoint' Menstruum In Power Apps Upload Multiple Files To A SharePoint Document Library Add together Metadata To A SharePoint Document Library Display Recently Uploaded Files        

Introduction: The Submit A Contract App

The Submit A Contract app is used past salespeople at a bakery to upload contract files to a SharePoint document library. Once a contract is signed the salesperson attaches the file, adds some metadata (customer name, contract date and client type) to help go along the contracts organized and presses the upload button to submit the file

Setup The SharePoint Document Library

Add a new SharePoint document library chosen Contracts with the post-obit columns and types:

  • Name (single-line text)
  • CustomerName (unmarried-line text)
  • SoldDate (Date just)
  • Industry (single-line text)

The document library will wait like this once we upload some files later in the tutorial.

Insert An Attachments Field

In the Submit A Contract app a salesperson needs to add a file to an attachments field and upload information technology to SharePoint. Open up Power Apps and Create a new app from blank. So insert a few labels and icons to make it wait like the screenshot below.

The attachments field cannot exist inserted from the carte du jour then we must use a workaround. Get to the data tab on the left menu and add any existing SharePoint list from your SharePoint site. Do not add the Contracts SharePoint document library we created before. We cannot use it to generate an attachments field.

Create a new Edit Form with your SharePoint listing as the data source. The attachments control should automatically appear when we create the class. If it does not, y'all can add the attachments field using Edit fields on the correct-side carte.

Cutting the attachments command and paste it outside the grade. Delete the form.

Use the following backdrop in the attachments control:

          Items: Blank() DisplayMode: DisplayMode.Edit MaxAttachments: 1        

Our app at present has an attachments field we tin use to upload the contract documents. We can at present delete connection to the SharePoint listing. Information technology 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 Power Apps. Nosotros will demand to create a Power Automate flow to do it instead. Open the Ability Automate activity from the top menu and select Create a new flow.

Cull the Power Apps button template.

Name the flow UploadFileToDocument library and click Save.

Nosotros desire to utilize the PowerApps (V2) trigger because it supports files as an input type whereas the PowerApps trigger does non. Delete the PowerApps trigger and add PowerApps(V2) in its place.

Select the File input type. Name the input File Content. Make File Content a required input.

Add together a SharePoint action to the menses: Create File. Use your SharePoint site address and document library folder path as inputs. The File Content field should reference the file establish in our flow trigger.

File Name requires a period expression. Open the flow expression editor then copy + paste this lawmaking into the File Name field.

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

Nosotros are now done creating the flow to upload a document.

Connect The 'Upload To SharePoint' Catamenia In Ability Apps

Go back to PowerApps and add a button. Select the OnSelect property and click on the UploadFileToDocumentLibrary field in the Power Automate menu.

The flow will appear every bit a connexion in the data tab.

Remove any code from the Upload button's OnSelect property and supersede it with this code. A file must exist passed equally an object to Ability Automate. The contentBytes field holds a reference to the attachment file and name stores the filename and extension.

          UploadFileToDocumentLibrary.Run(      {          contentBytes: First(att_SubmitContract_AttachFile.Attachments).Value,          name: Outset(att_SubmitContract_AttachFile.Attachments).Name      }  );        


Note: if you are receiving an error when passing the file to the menses make certain you have set the flow input to be a required field.

We're done creating the 'upload a certificate to a SharePoint library' functionality. Test your app to make certain its working.

The contract certificate should announced in your SharePoint site as shown beneath.

Upload Multiple Files To A SharePoint Certificate Library (Optional)

If we wanted to include the ability to upload multiple files at the same time we could modify the OnSelect property of the upload push to loop through each attachment and run the flow in one case per file. Nosotros will as well need to increment the MaxAttachments property of the attachment command from i to some other value.

          ForAll(     att_DocLib_SubmitContract.Attachments Equally Certificate,     UploadFileToDocumentLibrary.Run(         {             contentBytes: Document.Value,             name: Document.Name         }     ) );        

Since this is an optional step, the rest of this article will assume you have used the single-file upload method.

Add Metadata To A SharePoint Certificate Library

The salesperson must as well include additional data about the contract to keep the contracts files organized. The technical term for this is metadata: "information-about-data". Merely most folks but telephone call it tagging documents.

Add a few text inputs (Customer Proper noun, Industry) and a engagement picker (Contract Date) every bit shown below to capture the metadata.

We must update the Upload Document To A SharePoint Library flow to insert the metadata from Power Apps. Modify the Power Apps (V2) trigger action to add three new inputs as shown below. They should all exist required inputs.

Then add another action at the lesser of the flow: SharePoint – Update file backdrop

Now we are done updating the Flow. Go back to Power Apps…

…and update the OnSelect property of the upload button with this additional code to laissez passer the new parameters. Observe that the parameter names practise non match the names nosotros defined in catamenia. They are generic names based on the data type.

          UploadFileToDocumentLibrary.Run(      {          contentBytes: Outset(att_SubmitContract_AttachFile.Attachments).Value,          proper noun: Commencement(att_SubmitContract_AttachFile.Attachments).Proper name      },      txt_SubmitContract_CustName.Text,      Text(          dte_SubmitContract_ContractDate.SelectedDate,          "[$-en-US]yyyy-mm-dd"      ),      txt_SubmitContract_ClientType.Text  );        

Nosotros tin can now include metadata with the document at the time of upload to SharePoint. Give this new functionality a examination 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 characteristic, connect the app to the Contract certificate library in SharePoint.

Then add a gallery to the Submit A Contract app that looks like the screenshot below.

Utilise this code in the Items property 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 date modified label.

          ThisItem.Modified        

That'due south it, we're done!

Questions?

If yous have any questions or feedback about Ability Apps Easiest Way To Upload Files To A SharePoint Document Library please leave a message 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.

kellygrapir.blogspot.com

Source: https://www.matthewdevaney.com/power-apps-easiest-way-to-upload-files-to-a-sharepoint-document-library/

Postar um comentário for "Windows App to Upload Documents to Sharepoint"