We have an SharePoint online environment in which we have created a records collection. We are trying to sync one of our network shares to a document library in this collection and we want to set this job on a windows server.

The network share will be updated with new files on a daily basis and we want the files to be synced to the document library automatically without any user intervention.

Can we set this up by One Drive or does it demand any custom solutions?

  • You are going to want to roll something custom, a One Drive sync to a SharePoint document library can currently only sync 5000 items. Aug 26, 2016 at 18:45
  • @EricAlexander Currently there are few hundred files and they will be purged or overwritten on a regular basis. So the total number of files will be less than 5000 Aug 26, 2016 at 19:03
  • I'd still recommend PowerShell or a CSOM console application to do it, using consumer applications for business functions feels brittle. Aug 26, 2016 at 19:10

2 Answers 2


The sync client does not really cover service type sync scenarios. The client is intended to allow a user quick access to local files where the user can make local changes and then push them back to the server. The scenario described is more like a custom load solution where documents are generated by a third party system and then imported into SharePoint for document lifecycle management.

On the other hand, a single migration of content on-prem into the cloud would allow for better management of the documents. Things like metadata and other controls might be lost when editing files outside of the SharePoint environment on the file share. Depending on the complexity of the setup, this can be done yourself or though Microsoft or another third-party.


Based on the Answers and comments, we have developed our own custom solution. Here is a crude version of it.

static void Main ( string [ ] args )
    var targetSite = new Uri ( "https://company.sharepoint.com/Sites/CollectionName/" );
    var login = "[email protected]";
    var password = "password";
    var securePassword = new SecureString ( );
    foreach ( char c in password )
        securePassword.AppendChar ( c );

    var onlineCredentials = new SharePointOnlineCredentials ( login, securePassword );

    using ( ClientContext clientContext = new ClientContext ( targetSite ) )
        clientContext.Credentials = onlineCredentials;
        Web web = clientContext.Web;
        List docs = web.Lists.GetByTitle ( "Record Library" );
        clientContext.Load ( docs.RootFolder.Files );

        clientContext.ExecuteQuery ( );

        FileCollection fc = docs.RootFolder.Files;

        DirectoryInfo directoryInfo = new DirectoryInfo ( @"\\Shared Network Path\" );
        FileInfo [ ] files = directoryInfo.GetFiles ( "*.pdf" ).ToArray ( );

        foreach ( FileInfo file in files )
            if ( !fc.Any ( x => x.Name == file.Name ) )
                FileCreationInformation newFile = new FileCreationInformation ( );
                newFile.Content = System.IO.File.ReadAllBytes ( file.FullName );
                newFile.Url = file.Name;

                docs.RootFolder.Files.Add ( newFile );
        clientContext.ExecuteQuery ( );
        Console.Read ( );

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.