/// <summary> /// Backups SharePoint site collection. /// </summary> /// <param name="itemId">Site collection id within metabase.</param> /// <param name="fileName">Backed up site collection file name.</param> /// <param name="zipBackup">A value which shows whether back up must be archived.</param> /// <param name="download">A value which shows whether created back up must be downloaded.</param> /// <param name="folderName">Local folder to store downloaded backup.</param> /// <returns>Created backup file name. </returns> public static string BackupSiteCollection(int itemId, string fileName, bool zipBackup, bool download, string folderName) { // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(null); } // Load original meta item SharePointEnterpriseSiteCollection origItem = (SharePointEnterpriseSiteCollection)PackageController.GetPackageItem(itemId); if (origItem == null) { return(null); } // Log operation. TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "BACKUP_SITE_COLLECTION", origItem.Name, itemId); try { // Create site collection on server. HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId); string backFile = hostedSharePointServer.Enterprise_BackupSiteCollection(origItem.Name, fileName, zipBackup); if (!download) { // Copy backup files to space folder. string relFolderName = FilesController.CorrectRelativePath(folderName); if (!relFolderName.EndsWith("\\")) { relFolderName = relFolderName + "\\"; } // Create backup folder if not exists if (!FilesController.DirectoryExists(origItem.PackageId, relFolderName)) { FilesController.CreateFolder(origItem.PackageId, relFolderName); } string packageFile = relFolderName + Path.GetFileName(backFile); // Delete destination file if exists if (FilesController.FileExists(origItem.PackageId, packageFile)) { FilesController.DeleteFiles(origItem.PackageId, new string[] { packageFile }); } byte[] buffer = null; int offset = 0; do { // Read remote content. buffer = hostedSharePointServer.Enterprise_GetTempFileBinaryChunk(backFile, offset, FILE_BUFFER_LENGTH); // Write remote content. FilesController.AppendFileBinaryChunk(origItem.PackageId, packageFile, buffer); offset += FILE_BUFFER_LENGTH; }while (buffer.Length == FILE_BUFFER_LENGTH); } return(backFile); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }