We used to utilize the UiPathTeam.Sharepoint.Activities to manipulate SharePoint list items. We’re currently in an effort to migrate away from “Windows-legacy” compatibility automations. The UiPathTeam.Sharepoint.Activities package is not available for “Windows” compatible automations.
We’ve been able to replace the functionality we’ve used with other activities and with direct SharePoint API calls.
We’re struggling with attaching files to list items. We’ve had some success using the SharePoint API endpoint: POST “/_api/lists/GetByTitle(‘’)/items(”<List Item ID")/AttachmentFiles/add(FileName=‘<file name’) But we’re not quite there.
We successfully get a file attached to the list item using that endpoint, but the data is always corrupted in some way.
We’ve tried 2 primary ways.
The first is to use “File attachments” property of UiPath.Web.Activities.HttpClient. This is of type ICollection. We’re using “Path Exists” to get ILocalResource references to fill the collection. When we do this, we end up with files attached to the list item, but with an erroneous header and footer:
-----------8B43D14A-4F58-49DE-B617-EE104D985B62
Content-Disposition: form-data; name=“testfile”; filename=“testfile.png”
Content-Type: application/octet-stream
‰PNG
-----------8B43D14A-4F58-49DE-B617-EE104D985B62–
If I use a text editor to remove everything but the binary part, the file works correctly, but it does not work correctly with those headers/footers there.
The second method we’ve tried is to read the file data in with System.IO.File.ReadAllBytes, encoding the data as a string, and sending that file data as the body of the HTTP request. This also attaches a file to the SharePoint list item, but it is junk data. I expect I’m not encoding it properly.
Does anyone have any insights and/or has anyone had luck using other methods to attach files to SharePoint list items?