public static void UploadEmail(SharePointListViewControl listviewControl, ISPCFolder dragedFolder, DragEventArgs e, List <EUEmailUploadFile> emailUploadFiles, bool isListItemAndAttachmentMode) { try { EUFieldInformations fieldInformations = null; EUFieldCollection fields = null; UploadProgressForm uploadProgressForm = new UploadProgressForm(); if (EUSettingsManager.GetInstance().Settings == null) { MessageBox.Show("You need to configure settings first."); SettingsForm settingsControl = new SettingsForm(); settingsControl.ShowDialog(); return; } if (dragedFolder as EUFolder != null) { EUFolder dragedSPFolder = dragedFolder as EUFolder; List <EUContentType> contentTypes = SharePointManager.GetContentTypes(dragedSPFolder.SiteSetting, dragedSPFolder.WebUrl, dragedSPFolder.ListName); fields = SharePointManager.GetFields(dragedSPFolder.SiteSetting, dragedSPFolder.WebUrl, dragedSPFolder.ListName); ListItemEditForm listItemEditForm = new ListItemEditForm(); listItemEditForm.InitializeForm(dragedSPFolder, null); listItemEditForm.ShowDialog(); if (listItemEditForm.DialogResult != DialogResult.OK) { return; } foreach (EUEmailUploadFile emailUploadFile in emailUploadFiles) { emailUploadFile.FieldInformations = listItemEditForm.FieldInformations; } } string sourceFolder = EUSettingsManager.GetInstance().CreateATempFolder(); if (EUSettingsManager.GetInstance().Settings.UploadAutomatically == true || dragedFolder as FSFolder != null || dragedFolder as GFolder != null) { if (listviewControl != null) { for (int i = 0; i < emailUploadFiles.Count; i++) { EUEmailUploadFile emailUploadFile = emailUploadFiles[i]; listviewControl.LibraryContentDataGridView.Rows.Insert(i, 1); listviewControl.LibraryContentDataGridView.Rows[i].Tag = emailUploadFile.UniqueID.ToString(); if (dragedFolder as EUFolder != null) { listviewControl.LibraryContentDataGridView.Rows[i].Cells["ExtensionImageColumn"].Value = Sobiens.Office.SharePointOutlookConnector.Properties.Resources.ajax_loader; } string title = emailUploadFile.FilePath.Split('\\')[emailUploadFile.FilePath.Split('\\').Length - 1]; listviewControl.LibraryContentDataGridView.Rows[i].Cells["TitleColumn"].Value = title; } } // JOEL JEFFERY 20110712 Hook up the UploadFailed event // JON SILVER JULY 2011 Hook up the UploadSucceeded event if (!addedEventHandler) { OutlookConnector.GetConnector(dragedFolder.SiteSetting).UploadFailed += new EventHandler(EUEmailManager_UploadFailed); OutlookConnector.GetConnector(dragedFolder.SiteSetting).UploadSucceeded += new EventHandler(EUEmailManager_UploadSucceeded); addedEventHandler = true; } OutlookConnector.GetConnector(dragedFolder.SiteSetting).UploadFiles(dragedFolder, emailUploadFiles, fields, fieldInformations, listviewControl); } else { uploadProgressForm.Initialize(dragedFolder, sourceFolder, emailUploadFiles, isListItemAndAttachmentMode, fieldInformations); uploadProgressForm.ShowDialog(); } } catch (System.Exception ex) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogManager.LogAndShowException(methodName, ex); throw ex; } }
public void UploadItems(object _uploadItems) { bool uploadSucceeded = false; List <EUUploadItem> uploadItems = (List <EUUploadItem>)_uploadItems; FileExistDialogResults lastFileExistDialogResults = FileExistDialogResults.NotSelected; bool doThisForNextConflicts = false; foreach (EUUploadItem uploadItem in uploadItems) { string newDestinationUrl = uploadItem.DestinationFolderUrl + "/"; string copySource = new FileInfo(uploadItem.EmailUploadFile.FilePath).Name; string[] copyDest = new string[1] { uploadItem.DestinationFolderUrl + "/" + copySource }; byte[] itemByteArray = SharePointManager.ReadByteArrayFromFile(uploadItem.EmailUploadFile.FilePath); EUListItem listItem; string newFileName = copySource; IOutlookConnector connector = OutlookConnector.GetConnector(uploadItem.Folder.SiteSetting); if ( (doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Skip) || lastFileExistDialogResults == FileExistDialogResults.Cancel) { uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.EmailUploadFile.UniqueID); continue; } bool isCurrentFileUploadCanceled = false; if ( (doThisForNextConflicts == false) || (doThisForNextConflicts == true && lastFileExistDialogResults == FileExistDialogResults.Copy) ) { while (connector.CheckFileExistency(uploadItem.Folder, null, newFileName) == true) { FileExistConfirmationForm fileExistConfirmationForm = new FileExistConfirmationForm(copyDest[0]); fileExistConfirmationForm.ShowDialog(); lastFileExistDialogResults = fileExistConfirmationForm.FileExistDialogResult; doThisForNextConflicts = fileExistConfirmationForm.DoThisForNextConflicts; newFileName = fileExistConfirmationForm.NewFileName; if (lastFileExistDialogResults == FileExistDialogResults.Skip || lastFileExistDialogResults == FileExistDialogResults.Cancel) { uploadItem.SharePointListViewControl.DeleteUploadItemInvoke(uploadItem.EmailUploadFile.UniqueID); isCurrentFileUploadCanceled = true; break; } if (lastFileExistDialogResults == FileExistDialogResults.CopyAndReplace) { break; } string newCopyDest = copyDest[0].Substring(0, copyDest[0].LastIndexOf("/")) + "/" + newFileName; copyDest = new string[] { newCopyDest }; } } if (isCurrentFileUploadCanceled == true) { continue; } if (uploadItem.EmailUploadFile.IsListItemAndAttachment == false) { uint?result = SharePointManager.UploadFile(uploadItem.Folder.SiteSetting, uploadItem.Folder.ListName, uploadItem.Folder.RootFolderPath, uploadItem.Folder.SiteUrl, uploadItem.Folder.WebUrl, copySource, copyDest, itemByteArray, uploadItem.Fields, uploadItem.EmailUploadFile.MetaData, uploadItem.EmailUploadFile.FieldInformations, out listItem); if (uploadItem.SharePointListViewControl != null && listItem != null) // JON SILVER JULY 2011 - Is this success??? { uploadItem.SharePointListViewControl.NotifyUploadItemInvoke(uploadItem.EmailUploadFile.UniqueID, listItem); } // JON SILVER JULY 2011 if (result.HasValue && listItem != null) { uploadSucceeded = true; } } else { int?result = SharePointManager.UploadListItemWithAttachment(uploadItem); uploadSucceeded = result.HasValue; } } // JON SILVER JULY 2011 - RAISE UPLOAD SUCCESS SO WE CAN DELETE IF WE ARE MOVING if (!uploadSucceeded && UploadFailed != null) //why is UploadFailed null sometimes? JJ { UploadFailed(this, new EventArgs()); } else if (UploadSucceeded != null) { UploadSucceeded(this, new EventArgs()); } }