예제 #1
0
        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());
            }
        }
예제 #2
0
        public void Upload()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new UploadDelegate(Upload));
            }
            else
            {
                ErrorLabel.Visible = false;

                ProgressValueLabel.Text = "Started.";
                ProgressValueLabel.Refresh();
                SetButtonEnabilityOnUploading();
                int            totalRows = EmailsListView.Items.Count;
                List <EUField> fields    = SharePointManager.GetFields(_siteSetting, _webURL, _listName);
                SharePointCopyWS.CopyResult[] myCopyResultArray = null;
                string log      = String.Empty;
                bool   hasError = false;
                if (_isListItemAndAttachmentMode == false)
                {
                    for (int i = 0; i < EmailsListView.Items.Count; i++)
                    {
                        if (backgroundWorker1.CancellationPending == true)
                        {
                            ProgressValueLabel.Text = "Cancelled.";
                            ProgressValueLabel.Refresh();
                            return;
                        }
                        ListViewItem listViewItem = EmailsListView.Items[i];
                        if (listViewItem.Checked == false)
                        {
                            continue;
                        }
                        EUEmailMetaData metaData    = listViewItem.Tag as EUEmailMetaData;
                        string          filename    = listViewItem.SubItems[1].Text;
                        string          newFilename = listViewItem.Text;
                        ProgressValueLabel.Text = newFilename + " is being uploaded...";
                        ProgressValueLabel.Refresh();
                        string filePath      = _sourceFolder + "\\" + filename;
                        byte[] itemByteArray = SharePointManager.ReadByteArrayFromFile(filePath);
                        string sourceDest    = _destinationFolderUrl + "/" + newFilename;

                        string[]   sourceDests = new string[] { sourceDest };
                        EUListItem listItem;
                        SharePointManager.UploadFile(_siteSetting, _listName, _rootFolderPath, _siteURL, _webURL, newFilename, sourceDests, itemByteArray, fields, metaData, _fieldInfoArray, out listItem);

                        /*
                         * foreach (SharePointCopyWS.CopyResult copyResult in myCopyResultArray)
                         * {
                         *  if (copyResult.ErrorCode != Sobiens.Office.SharePointOutlookConnector.SharePointCopyWS.CopyErrorCode.Success)
                         *      hasError = true;
                         *  log += "DestinationUrl:" + copyResult.DestinationUrl + Environment.NewLine + "ErrorCode:" + copyResult.ErrorCode.ToString() + Environment.NewLine + "ErrorMessage:" + copyResult.ErrorMessage + Environment.NewLine;
                         * }
                         * LogManager.Log(log, EULogModes.Normal);
                         */
                        SetProgressBar(i, totalRows);
                    }
                }
                else
                {
                    Hashtable emails = new Hashtable();

                    for (int i = 0; i < EmailsListView.Items.Count; i++)
                    {
                        ListViewItem listViewItem = EmailsListView.Items[i];
                        //DataGridViewRow dataGridViewRow = EmailsDataGridView.Rows[i];
                        //bool included = (bool)dataGridViewRow.Cells["Included"].Value;
                        if (listViewItem.Checked == false)
                        {
                            continue;
                        }
                        Microsoft.Office.Interop.Outlook.MailItem emailItem = listViewItem.Tag as Microsoft.Office.Interop.Outlook.MailItem;
                        if (emails[emailItem.EntryID] == null)
                        {
                            emails[emailItem.EntryID] = new List <ListViewItem>();
                        }
                        ((List <ListViewItem>)emails[emailItem.EntryID]).Add(listViewItem);
                    }
                    totalRows = emails.Count;
                    int currentIndex = 0;
                    foreach (object attachmentsObject in emails.Values)
                    {
                        if (backgroundWorker1.CancellationPending == true)
                        {
                            ProgressValueLabel.Text = "Cancelled.";
                            ProgressValueLabel.Refresh();
                            return;
                        }
                        List <ListViewItem> attachments   = (List <ListViewItem>)attachmentsObject;
                        ListViewItem        attachmentRow = attachments[0];
                        Microsoft.Office.Interop.Outlook.MailItem emailItem = attachmentRow.Tag as Microsoft.Office.Interop.Outlook.MailItem;
                        string body = emailItem.Body;
                        int    id   = SharePointManager.CreateListItem(_siteSetting, _rootFolderPath, _webURL, _listName, emailItem.Subject, body);

                        foreach (ListViewItem attachmentRow1 in attachments)
                        {
                            //string filename = attachmentRow1.Cells["Filename"].Value.ToString();
                            //string newFilename = attachmentRow1.Cells["NewFilename"].Value.ToString();
                            string filename    = attachmentRow1.SubItems[0].Text;
                            string newFilename = attachmentRow1.Text;
                            ProgressValueLabel.Text = newFilename + " is being uploaded...";
                            ProgressValueLabel.Refresh();
                            string filePath      = _sourceFolder + "\\" + filename;
                            byte[] itemByteArray = SharePointManager.ReadByteArrayFromFile(filePath);
                            string result        = SharePointManager.AddAttachment(_siteSetting, _webURL, _listName, id, newFilename, itemByteArray);

                            log += "WebURL:" + _webURL + Environment.NewLine + "ListName:" + _listName + Environment.NewLine + "filePath:" + filePath + Environment.NewLine + "newFilename:" + newFilename + Environment.NewLine + "result:" + result + Environment.NewLine;
                            LogManager.Log(log, EULogModes.Normal);
                        }
                        SetProgressBar(currentIndex, totalRows);
                        currentIndex++;
                    }
                }
                CurrentUploadLog = log;
                if (hasError == true)
                {
                    ErrorLabel.Visible = true;
                }
            }
        }