/// <summary> /// Migrates the file. /// </summary> /// <param name="file">file to migrate</param> /// <param name="specification">specifications for the migration</param> /// <param name="targetWeb">the target web</param> internal void MigrateFile(File file, FileMigrationSpecification specification, Web targetWeb) { SharePoint2010And2013Downloader downloader = new SharePoint2010And2013Downloader(specification); SharePoint2010And2013Uploader uploader = new SharePoint2010And2013Uploader(specification.TargetClientContext); try { MigrationFile migrationFile = downloader.DownloadDocument(file); Console.WriteLine("downloaded file '{0}'.", migrationFile.File.Name); //// specification.Logger.AddMessage(string.Format("downloaded file '{0}'.", migrationFile.File.Name)); Thread.Sleep(this.GetWaitingTime(specification.Bandwith)); uploader.UploadDocument(migrationFile, targetWeb); Console.WriteLine("uploaded file '{0}'.", migrationFile.File.Name); ////specification.Logger.AddMessage(string.Format("uploaded file '{0}'.", migrationFile.File.Name)); } catch (OperationCanceledException e) { Console.WriteLine("Exception: {0}", e.Message); //// specification.Logger.AddMessage(string.Format("Exception: {0}", e.Message)); } }
/// <summary> /// Uploads the document. /// </summary> /// <param name="migrationFile">the migration file</param> /// <param name="targetWeb">the target web</param> internal void UploadDocument(MigrationFile migrationFile, Web targetWeb) { Console.WriteLine("Upload file '{0}' now.", migrationFile.File.Name); Folder rootFolder = targetWeb.RootFolder; this.targetClientContext.Load(rootFolder); this.targetClientContext.ExecuteQuery(); FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = migrationFile.Content; newFile.Overwrite = true; newFile.Url = this.GetSharedDocumentsUrl(rootFolder) + migrationFile.File.Name; File file; Folder folder = this.GetSharedDocumentsFolder(rootFolder); file = folder.Files.Add(newFile); this.targetClientContext.ExecuteQuery(); }
/// <summary> /// Downloads the document. /// </summary> /// <param name="file">file to download</param> /// <returns>instance of MigrationFile to migrate</returns> internal MigrationFile DownloadDocument(File file) { ClientContext sourceClientContext = this.specification.SourceClientContext; Console.WriteLine("Downlaod file '{0}' now.", file.Name); FileInformation fileInformation = File.OpenBinaryDirect(sourceClientContext, file.ServerRelativeUrl); sourceClientContext.ExecuteQuery(); byte[] content = this.ReadFully(fileInformation.Stream); if (content.Length > this.specification.MaxFileSize) { throw new OperationCanceledException("Filesize of file '" + file.Name + "' is too big for upload."); } MigrationFile migrationFile = new MigrationFile(); migrationFile.File = file; migrationFile.Content = content; return(migrationFile); }