0

I was working with Sync feature of document library. In this feature, a user can Sync document library to the local machine.

enter image description here

What I am looking for is if there is a way to do the same with Programmatically(C# or other language)

Happy coding :)

3 Answers 3

1

As @Amy_MSFT states, this is complex. I was given this exact task, and after some research, here is what my approach was.

I wanted something that exactly simulates clicking the "Sync" button for a library. So, I knew I had to generate the sync links, and either force the click event, or have the user click a link to kick off the sync.

The link behind that "Sync" button can be built using this article: How to Manually Create a OneDrive Sync Link from Your SharePoint Page

I wrote an SPFx webpart using typescript/React that pulls all of the libraries for the given site and then generates link buttons to be clicked to sync each library. What I've found is the One Drive application can only handle one sync action at a time, so auto-clicking these links with code didn't work. If you find a way around this, I'd love to hear about it.

The user experience isn't quite what I wanted, but it's certainly a lot quicker and easier than going to each library to sync.

1
  • Sounds good but we have took another approach where we are not doing sync but this sounds like a step in the right direction Commented Mar 25, 2020 at 0:36
0

If you want to achieve the sync feature programmatically, it is complex. It will upload and download the files many times.

You could use OneDrive app to sync documents from SharePoint online to local machine.

More references:

Upload File to SharePoint Office 365 Programmatically using C# CSOM – PNP.

Download file from SharePoint Online.

Updated:

Yes, you can create the folder programmatically and set the folder as sync folder in OneDrive app.

More reference:

How to: Create a File or Folder (C# Programming Guide).

C# Directory.CreateDirectory, Create New Folder.

3
  • Thanks for the response @amy_MSFT. I do agree that syncing files is complex. What I want to do is create a sync folder programmatically then OneDrive Sync will do the sync. Commented Oct 11, 2019 at 15:11
  • I have updated the reply.
    – Amy_MSFT
    Commented Oct 15, 2019 at 7:57
  • Thanks for sharing the link and updating answer but the links don't have details on how to setup folder and sync folder. Commented Oct 21, 2019 at 16:15
0

I watched this youtube video and then I wrote a PowerShell script that runs when the user signs in. It is working ok... although, it could be better.

https://youtu.be/Zoac9lbUuG0?t=929

1
  • Its been a while since I worked on this so no longer relevant for me but might be helpful for someone else. Thanks for sharing. Commented Mar 9, 2022 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.