public LoginForm() { InitializeComponent(); CloseFlag = LoginFormFlag.Close_Exit; SPSiteCollectionURL = ""; UserCredentials = new System.Net.NetworkCredential(); deLogin = new DocExtractor(); }
public MainForm() { InitializeComponent(); DownloadType = "Folders and Files"; de = new DocExtractor(); myAboutForm = new AboutForm(); }
private void PerformExit() { // dispose objects de = null; SiteLoginForm = null; FileDownloadForm = null; myAboutForm = null; Application.Exit(); }
public DownloaderForm(string SCurl, List <string> FileRefUrls, string DestDir, string WhatToDownload) { InitializeComponent(); FilesList = FileRefUrls; OutputDir = DestDir; DownloadType = WhatToDownload; de2 = new DocExtractor(); de2.SiteUrl = SCurl; progressBar1.Value = 0; FilesDownloaded = 0; FilesMissed = 0; FilesProcessed = 0; }
public DownloaderForm(string SCurl, List<string> FileRefUrls, string DestDir, string WhatToDownload) { InitializeComponent(); FilesList = FileRefUrls; OutputDir = DestDir; DownloadType = WhatToDownload; de2 = new DocExtractor(); de2.SiteUrl = SCurl; progressBar1.Value = 0; FilesDownloaded = 0; FilesMissed = 0; FilesProcessed = 0; }
// Begin the downloading of files with the ability to cancel private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string fileName = ""; string diskFullPath = ""; int FileCount = FilesList.Count; int ProgressValue = 0; float ProgressIndex = (float)FileCount / 100; string LogMsg = "***** DocExtractor for SharePoint Log File *****\r\n" + "***** V1.0.0.0 by Eng. Ibraheem 2012 *****\r\n" + "************************************************\r\n\r\n" + "Created at: " + System.DateTime.Now.ToString() + "\r\n" + "Site Collection: " + de2.SiteUrl + "\r\n" + "\r\n\r\n"; // enhancement: add the crieteria info string LogErrorFiles = ""; if (DownloadType == "Files_and_Folders") { string FolderName = ""; string[] UrlSplitArray; foreach (string relativeUrl in FilesList) { diskFullPath = OutputDir; UrlSplitArray = relativeUrl.Split('/'); for (int i = 0; i < UrlSplitArray.Length - 1; i++) { FolderName = UrlSplitArray[i]; if (FolderName == "" || FolderName == null) { //FolderName = "Home"; i++; continue; // to neglect the '/Lists/' portion } diskFullPath += @"/" + FolderName; if (!File.Exists(diskFullPath)) { System.IO.Directory.CreateDirectory(diskFullPath); // create the dir } } fileName = UrlSplitArray[UrlSplitArray.Length - 1]; // last item is the file name diskFullPath += @"/" + fileName; try { byte[] fileData = de2.getFileData(relativeUrl); // works for files in doc libs using (FileStream outStream = new FileStream(diskFullPath, FileMode.Create)) // create file in that directory { outStream.Write(fileData, 0, fileData.Count()); //outStream.Close(); } // prepare a row in log file LogMsg += relativeUrl + " downloaded.\r\n"; } catch (Exception ex) { // write file name and error msg in log file LogErrorFiles += relativeUrl + " download failed: " + ex.Message + "\r\n"; FilesMissed++; } // Updating progress bar FilesProcessed++; ProgressValue = (int)Math.Ceiling(FilesProcessed / ProgressIndex); if (ProgressValue > 100) { ProgressValue = 100; } worker.ReportProgress(ProgressValue); // for cancelling the download by user if (worker.CancellationPending == true) { e.Cancel = true; break; } } } else // if (DownloadType == "Files_only") { foreach (string relativeUrl in FilesList) { fileName = relativeUrl.Substring(relativeUrl.LastIndexOf("/") + 1); diskFullPath = OutputDir + fileName; // make entry for each file count try { FileCopies.Add(diskFullPath, 0); // 1st time for file } catch (ArgumentException) { FileCopies[diskFullPath] = FileCopies[diskFullPath] + 1; // file entry already exists } // make a file copy when file already exists in output dir if (File.Exists(diskFullPath)) { // add the "_Copy(x)" before the file extension // ext = fileName.Substring(fileName.IndexOf('.')); // .jpg // name_before_ext = fileName.Remove(fileName.LastIndexOf('.')) diskFullPath = OutputDir + fileName.Remove(fileName.LastIndexOf('.')) + "_Copy(" + FileCopies[diskFullPath] + ")" + fileName.Substring(fileName.IndexOf('.')); } try { byte[] fileData = de2.getFileData(relativeUrl); // works for files in doc libs using (FileStream outStream = new FileStream(diskFullPath, FileMode.Create)) // create file in that directory { outStream.Write(fileData, 0, fileData.Count()); //outStream.Close(); } // prepare a row in log file LogMsg += relativeUrl + " downloaded.\r\n"; } catch (Exception ex) { // write file name and error msg in log file LogErrorFiles += relativeUrl + " download failed: " + ex.Message + "\r\n"; FilesMissed++; } // Updating progress bar FilesProcessed++; ProgressValue = (int)Math.Ceiling(FilesProcessed / ProgressIndex); if (ProgressValue > 100) { ProgressValue = 100; } worker.ReportProgress(ProgressValue); // for cancelling the download by user if (worker.CancellationPending == true) { e.Cancel = true; break; } } } // add the section for failed files in log LogMsg += "\r\n------------------------------ Files that failed to download ------------------------------\r\n"; LogMsg += "\r\n- " + LogErrorFiles + "\r\n"; LogMsg += "\r\n-------------------------------------------------------------------------------------------\r\n"; LogMsg += "\r\nTotal number of files processed: " + FileCount.ToString() + " files\r\n"; FilesDownloaded = (int)FilesProcessed - FilesMissed; LogMsg += "Total number of files downloaded: " + FilesDownloaded.ToString() + " files\r\n"; // create the log file string LogPath = OutputDir + "_DocExtractor Log_" + System.DateTime.Now.Year.ToString() + "_" + System.DateTime.Now.Month + "_" + System.DateTime.Now.Day + ".txt"; System.IO.File.WriteAllText(LogPath, LogMsg); FileCopies = null; FilesList = null; de2 = null; }
// Begin the downloading of files with the ability to cancel private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string fileName = ""; string diskFullPath = ""; int FileCount = FilesList.Count; int ProgressValue = 0; float ProgressIndex = (float)FileCount / 100; string LogMsg = "***** DocExtractor for SharePoint Log File *****\r\n" + "***** V1.0.0.0 by Eng. Ibraheem 2012 *****\r\n" + "************************************************\r\n\r\n" + "Created at: " + System.DateTime.Now.ToString() + "\r\n" + "Site Collection: " + de2.SiteUrl + "\r\n" + "\r\n\r\n"; // enhancement: add the crieteria info string LogErrorFiles = ""; if (DownloadType == "Files_and_Folders") { string FolderName = ""; string[] UrlSplitArray; foreach (string relativeUrl in FilesList) { diskFullPath = OutputDir; UrlSplitArray = relativeUrl.Split('/'); for (int i = 0; i < UrlSplitArray.Length - 1; i++) { FolderName = UrlSplitArray[i]; if (FolderName == "" || FolderName == null) { //FolderName = "Home"; i++; continue; // to neglect the '/Lists/' portion } diskFullPath += @"/" + FolderName; if (!File.Exists(diskFullPath)) { System.IO.Directory.CreateDirectory(diskFullPath); // create the dir } } fileName = UrlSplitArray[UrlSplitArray.Length - 1]; // last item is the file name diskFullPath += @"/" + fileName; try { byte[] fileData = de2.getFileData(relativeUrl); // works for files in doc libs using (FileStream outStream = new FileStream(diskFullPath, FileMode.Create))// create file in that directory { outStream.Write(fileData, 0, fileData.Count()); //outStream.Close(); } // prepare a row in log file LogMsg += relativeUrl + " downloaded.\r\n"; } catch (Exception ex) { // write file name and error msg in log file LogErrorFiles += relativeUrl + " download failed: " + ex.Message + "\r\n"; FilesMissed++; } // Updating progress bar FilesProcessed++; ProgressValue = (int)Math.Ceiling(FilesProcessed / ProgressIndex); if (ProgressValue > 100) ProgressValue = 100; worker.ReportProgress(ProgressValue); // for cancelling the download by user if (worker.CancellationPending == true) { e.Cancel = true; break; } } } else // if (DownloadType == "Files_only") { foreach (string relativeUrl in FilesList) { fileName = relativeUrl.Substring(relativeUrl.LastIndexOf("/") + 1); diskFullPath = OutputDir + fileName; // make entry for each file count try { FileCopies.Add(diskFullPath, 0); // 1st time for file } catch (ArgumentException) { FileCopies[diskFullPath] = FileCopies[diskFullPath] + 1; // file entry already exists } // make a file copy when file already exists in output dir if (File.Exists(diskFullPath)) { // add the "_Copy(x)" before the file extension // ext = fileName.Substring(fileName.IndexOf('.')); // .jpg // name_before_ext = fileName.Remove(fileName.LastIndexOf('.')) diskFullPath = OutputDir + fileName.Remove(fileName.LastIndexOf('.')) + "_Copy(" + FileCopies[diskFullPath] + ")" + fileName.Substring(fileName.IndexOf('.')); } try { byte[] fileData = de2.getFileData(relativeUrl); // works for files in doc libs using (FileStream outStream = new FileStream(diskFullPath, FileMode.Create))// create file in that directory { outStream.Write(fileData, 0, fileData.Count()); //outStream.Close(); } // prepare a row in log file LogMsg += relativeUrl + " downloaded.\r\n"; } catch (Exception ex) { // write file name and error msg in log file LogErrorFiles += relativeUrl + " download failed: " + ex.Message + "\r\n"; FilesMissed++; } // Updating progress bar FilesProcessed++; ProgressValue = (int)Math.Ceiling(FilesProcessed / ProgressIndex); if (ProgressValue > 100) ProgressValue = 100; worker.ReportProgress(ProgressValue); // for cancelling the download by user if (worker.CancellationPending == true) { e.Cancel = true; break; } } } // add the section for failed files in log LogMsg += "\r\n------------------------------ Files that failed to download ------------------------------\r\n"; LogMsg += "\r\n- " + LogErrorFiles + "\r\n"; LogMsg += "\r\n-------------------------------------------------------------------------------------------\r\n"; LogMsg += "\r\nTotal number of files processed: " + FileCount.ToString() + " files\r\n"; FilesDownloaded = (int)FilesProcessed - FilesMissed; LogMsg += "Total number of files downloaded: " + FilesDownloaded.ToString() + " files\r\n"; // create the log file string LogPath = OutputDir + "_DocExtractor Log_" + System.DateTime.Now.Year.ToString() + "_" + System.DateTime.Now.Month + "_" + System.DateTime.Now.Day + ".txt"; System.IO.File.WriteAllText(LogPath, LogMsg); FileCopies = null; FilesList = null; de2 = null; }