public static async Task RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("SharePoint File Mover Started");
            log.Info(await req.Content.ReadAsStringAsync());

            try
            {
                DropZoneInfo data = await req.Content.ReadAsAsync <DropZoneInfo>();

                bool success = RunFileMover(data);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message.ToString());
                log.Info(ex.StackTrace.ToString());
            }

            log.Info("SharePoint File Mover Completed");
        }
        private static bool RunFileMover(DropZoneInfo folderInfo)
        {
            string url                 = "";
            string appId               = ""; //replace it to your app id.
            string appScret            = ""; //replace it to your app secret.
            string documentLibraryName = folderInfo.listTitle;

            AuthenticationManager manager = new AuthenticationManager();

            using (ClientContext context = manager.GetAppOnlyAuthenticatedContext(url, appId, appScret))
            {
                Web web = context.Web;
                context.Load(web);

                List list = web.Lists.GetByTitle(documentLibraryName);

                CamlQuery query = new CamlQuery();

                ListItemCollection items = list.GetItems(query);
                context.Load(list.Fields);
                context.Load(list.RootFolder);
                context.Load(list.RootFolder.Folders);

                context.ExecuteQuery();

                foreach (Folder f in list.RootFolder.Folders)
                {
                    if (f.Name == folderInfo.currentFolder.Substring(folderInfo.currentFolder.LastIndexOf('/') + 1))
                    {
                        context.Load(f.Files,
                                     files => files.Include(file => file.Name),
                                     files => files.Include(file => file.ETag),
                                     files => files.Include(file => file.TimeLastModified),
                                     files => files.Include(file => file.ListItemAllFields["Company"]),
                                     files => files.Include(file => file.ListItemAllFields["CompliantReport"]),
                                     files => files.Include(file => file.ListItemAllFields["DocumentClass"]),
                                     files => files.Include(file => file.ListItemAllFields["DocumentType"]),
                                     files => files.Include(file => file.ListItemAllFields["Format"]),
                                     files => files.Include(file => file.ListItemAllFields["Language"]),
                                     files => files.Include(file => file.ListItemAllFields["Month"]),
                                     files => files.Include(file => file.ListItemAllFields["PlanYear"]),
                                     files => files.Include(file => file.ListItemAllFields["ProductType"])
                                     );

                        context.ExecuteQuery();

                        FileCollection filecol = f.Files;

                        List <FileDetails> pathfilecombo = GeneratePaths(filecol);

                        List <string> uniquePaths = pathfilecombo.Select(a => a.futurePath).Distinct().ToList();

                        CreatePaths(url, appId, appScret, uniquePaths, web);

                        HandleFileMove(pathfilecombo, web);
                    }
                }

                return(true);
            }
        }