/// <summary>
        /// Retrieve files from the selected SPOSite and create a csv
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnGetTargetFiles_Click(object sender, RoutedEventArgs e)
        {
            //We retrieve the selected list from the Treeview and related SPOSite
            string[] selection = getSelectedTreeview();

            //We instanciate the SPOLogic class
            SPOLogic spol = new SPOLogic(credential, selection[1]);

            //We retrieve the site Title
            string siteUrl  = selection[1];
            string siteName = siteUrl.Remove(0, (siteUrl.LastIndexOf("/")));

            //We retrieve the library Title
            var    list     = spol.getListName(selection[0]);
            string listName = list.RootFolder.Name.ToString();

            //We create the Site/Library Url to compute the Normalized path
            string siteLibUrl = string.Format("/sites{0}/{1}", siteName, listName);



            //We retrieve listitems from the selected library
            ListItemCollection listItems = spol.getLibraryFile(selection[0]);

            //We create the path of the csv file
            DateTime now         = DateTime.Now;
            var      date        = now.ToString("yyyy-MM-dd-HH-mm-ss");
            string   csvFileName = "GetListItem";
            var      appPath     = AppDomain.CurrentDomain.BaseDirectory;
            var      csvfilePath = $"{appPath}{csvFileName}{date}.csv";
            //We create the stringbuilder
            var csv    = new StringBuilder();
            var header = "Filepath,FileName,NormalizedPath,Hash";

            csv.AppendLine(header);

            //We loop the listitems to populate the csv
            foreach (ListItem listItem in listItems)
            {
                if (listItem.FileSystemObjectType == FileSystemObjectType.Folder)
                {
                    continue;
                }
                string filePath       = listItem.FieldValues["FileRef"].ToString();
                string normalizedPath = filePath.Replace(siteLibUrl, "");

                string fileActualPath = $"{selection[1]}/{selection[0]}/{listItem.FieldValues["FileLeafRef"]}";

                listItem.

                Logic.FileHash HashObj = new Logic.FileHash(fileActualPath);
                string         hash    = HashObj.CreateHash();

                var newLine = string.Format("{0},{1},{2},{3}", listItem.FieldValues["FileRef"], listItem.FieldValues["FileLeafRef"], normalizedPath, hash);
                csv.AppendLine(newLine);
            }

            System.IO.File.WriteAllText(csvfilePath, csv.ToString(), Encoding.UTF8);
            MessageBox.Show("Task done");
        }
        /// <summary>
        /// Migrate single file (2mb max) from local directory to library - test purpose
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        /*
         * private void Migrate_Click(object sender, RoutedEventArgs e)
         * {
         *  //We set up source and target strings
         *  string source = @"c:\tmp\test.txt"; //TBSource.Text;
         *  string target = TBTarget.Text;
         *
         *  // Call the SPOLogic object
         *  SPOLogic sp = new SPOLogic(credential, "https://toanan.sharepoint.com/sites/demo");
         *  try
         *  {
         *      //Try to copy the file and give success message
         *      sp.migrateLightFile(source, target);
         *      MessageBox.Show(string.Format("The file {0} has been migrated", source));
         *  }
         *  catch (Exception ex)
         *  {
         *      MessageBox.Show(ex.Message);
         *  }
         * }
         */

        /// <summary>
        /// Retrive file info from the selected path and create csv
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnGetSourceItems_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(TBSource.Text))
            {
                if (Directory.Exists(TBSource.Text))
                {
                    string sourcePath = TBSource.Text;
                    //We retrieve the sub dirinfos
                    List <DirectoryInfo> sourceFolders = getSourceFolders(sourcePath);

                    //We create the files fileinfo object
                    List <FileInfo> files = new List <FileInfo>();

                    // Start a task to loop on directories and retrieve file info
                    Task.Factory.StartNew(() =>
                    {
                        //And loop inside all dir to retrieve the files fileinfo
                        foreach (DirectoryInfo directory in sourceFolders)
                        {
                            List <FileInfo> Currentfiles = getSourceFiles(directory.FullName);
                            foreach (FileInfo fi in Currentfiles)
                            {
                                files.Add(fi);
                            }
                        }

                        //We create the path of the csv file
                        DateTime now       = DateTime.Now;
                        var date           = now.ToString("yyyy-MM-dd-HH-mm-ss");
                        string csvFileName = "Getfile";
                        var appPath        = AppDomain.CurrentDomain.BaseDirectory;
                        var csvfilePath    = $"{appPath}/logs/{csvFileName}{date}.csv";
                        Directory.CreateDirectory($"{appPath}/logs/");
                        //We create the stringbuilder to store file retrived information
                        var csv    = new StringBuilder();
                        var header = "Filepath,FileName,LastAccessTime,NormalizedPath,FileSize,Hash";
                        csv.AppendLine(header);

                        //Retrive fileinfo and write on csv file
                        foreach (FileInfo file in files)
                        {
                            var filePath           = file.FullName;
                            var fileLastAccess     = file.LastAccessTime;
                            var fileName           = file.Name;
                            var normalizedFilePath = file.FullName.Remove(0, sourcePath.Length);
                            var fileSize           = file.Length;

                            Logic.FileHash HashObj = new Logic.FileHash(filePath);
                            string hash            = HashObj.CreateHash();

                            var newLine = string.Format("{0},{1},{2},{3}", filePath, fileName, normalizedFilePath, hash);
                            csv.AppendLine(newLine);
                        }

                        System.IO.File.WriteAllText(csvfilePath, csv.ToString(), Encoding.UTF8);
                        MessageBox.Show("Task done");
                    });
                }
                else
                {
                    MessageBox.Show("No directory found in this path \nPlease double check");
                }
            }
            else
            {
                MessageBox.Show("Please choose a source path \nYou can use the browse button :)");
            }
        }