List Item Attachments

Data Sync does not include List Item Attachments this is because the SharePoint API would require a server round-trip per list item to get the meta data about this list and extra calls to get the file data.

Data Sync does however have some internal API calls on the SharePoint Client API connector that can be used via Project Automation to query for list item attachments and to add the attachments to an existing item.

API Returns Description
GetListItemAttachmentUrls(int itemid) List<string> List of attachment URLs
GetSharePointListService() Lists SharePoint Lists.asmx Web Service reference
GetSharePointWebService() Webs SharePoint Webs.asmx Web Service reference
GetWebClient() WebClient Authenticated .NET Framework WebClient object
GetListItemAttachment(string url) byte[] Downloads a byte array of the attachment file data
GetClientContext() ClientContext SharePoint Client Object Model ClientContext object

If we were to synchronise a list between two SharePoint sites either on the same server or a different server we can use these calls to get the item attachments from the source and add them to the target.

To do this we obtain a reference to the Lists.asmx Web Service for the target list, get a list of Attachment URL's from the source and then for each URL add it to the target list item.

We are using the AfterAddItem project automation items event to process list item attachments as item are ADDED to SharePoint. You will also likely need to implement the same for when items are UPDATED.

public override void AfterAddItem(object sender, DataCompareItemInvariant item, object identity)
    var listService = DataSourceB.GetSharePointListService();

    foreach(var url in DataSourceA.GetListItemAttachmentUrls(item.GetSourceIdentifier()))
        listService.AddAttachment(DataSourceB.ListName, identity.ToString(), System.IO.Path.GetFileName(url), DataSourceA.GetListItemAttachment(url));