private void MoveRoutedDocuments(List<EmailDocument> routedDocuments)
        {
            using (SPDocumentCopyService.Copy spDocumentCopyService = new SPDocumentCopyService.Copy())
            {
                spDocumentCopyService.Url = Config["SharePointSiteUrl"] + "_vti_bin/Copy.asmx";
                spDocumentCopyService.Credentials = CredentialCache.DefaultCredentials;

                foreach (EmailDocument document in routedDocuments)
                {
                    FieldInformation myFieldInfo = new FieldInformation();
                    FieldInformation[] basicFieldInfoArray = { myFieldInfo };
                    byte[] myByteArray;

                    uint myGetUint = spDocumentCopyService.GetItem(document.DocumentPath, out basicFieldInfoArray, out myByteArray);

                    CopyResult myCopyResult1 = new CopyResult();
                    CopyResult myCopyResult2 = new CopyResult();
                    CopyResult[] myCopyResultArray = { myCopyResult1, myCopyResult2 };

                    document.DocumentType = GetFilePropertyValue("Document Type", basicFieldInfoArray);
                    document.DocumentSubtype = GetFilePropertyValue("Document Subtype", basicFieldInfoArray);

                    FieldInformation fieldDocumentType = new FieldInformation { DisplayName = "Document Type Literal", InternalName = "DocumentTypeLiteral", Type = FieldType.Text, Value = document.DocumentType };
                    FieldInformation fieldDocumentSubType = new FieldInformation { DisplayName = "Document Subtype Literal", InternalName = "DocumentSubtypeLiteral", Type = FieldType.Text, Value = document.DocumentSubtype };

                    try
                    {
                        FieldInformation[] fullFieldInfoArray = { myFieldInfo, fieldDocumentType, fieldDocumentSubType };

                        uint myCopyUint = spDocumentCopyService.CopyIntoItems(document.DocumentPath, new string[] { document.DestinationUrl }, fullFieldInfoArray, myByteArray, out myCopyResultArray);

                        CopyResult copyResult = myCopyResultArray[0];

                        if (copyResult != null && copyResult.ErrorCode == SPDocumentCopyService.CopyErrorCode.Success)
                        {
                            document.RoutedSuccessfully = true;
                            document.RoutedDeletedSuccessfully = DeleteRoutedDocument(document);
                        }
                        else
                            document.RoutedSuccessfully = false;

                        if (myCopyUint != 0 || copyResult.ErrorCode != SPDocumentCopyService.CopyErrorCode.Success)
                        {
                            Logger logger = LogManager.GetCurrentClassLogger();
                            logger.Log(LogLevel.Error, "CopyRoutedDocuments: Exception occurred when copying a routed document", String.Concat(myCopyResultArray));
                        }

                        if (document.RoutedSuccessfully && document.RoutedDeletedSuccessfully)
                        {
                            LogDocumentRouting(document);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger logger = LogManager.GetCurrentClassLogger();
                        logger.Log(LogLevel.Error, "CopyRoutedDocuments: Exception occurred when copying a routed document", e);
                    }
                }
            }
        }
예제 #2
0
 public uint CopyIntoItems(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] Stream, out CopyResult[] Results) {
     object[] results1 = this.Invoke("CopyIntoItems", new object[] {
                 SourceUrl,
                 DestinationUrls,
                 Fields,
                 Stream});
     Results = ((CopyResult[])(results1[1]));
     return ((uint)(results1[0]));
 }
예제 #3
0
 public uint CopyIntoItemsLocal(string SourceUrl, string[] DestinationUrls, out CopyResult[] Results) {
     object[] results1 = this.Invoke("CopyIntoItemsLocal", new object[] {
                 SourceUrl,
                 DestinationUrls});
     Results = ((CopyResult[])(results1[1]));
     return ((uint)(results1[0]));
 }
        public void LoadMail(List<Email> emails)
        {
            using (SPDocumentCopyService.Copy spDocumentCopyService = new SPDocumentCopyService.Copy())
            {
                spDocumentCopyService.Credentials = CredentialCache.DefaultCredentials;

                foreach (Email email in emails)
                {

                    CopyResult myCopyResult1 = new CopyResult();
                    CopyResult myCopyResult2 = new CopyResult();
                    CopyResult[] myCopyResultArray = { myCopyResult1, myCopyResult2 };

                    FieldInformation from = new FieldInformation { DisplayName = "From Email", InternalName = "From Email", Type = FieldType.Text, Value = email.From };
                    FieldInformation title = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = email.Subject };
                    FieldInformation subject = new FieldInformation { DisplayName = "Email Subject", InternalName = "Email Subject", Type = FieldType.Text, Value = email.Subject };
                    FieldInformation body = new FieldInformation { DisplayName = "Email Body", InternalName = "Email Body", Type = FieldType.Text, Value = email.Body };
                    FieldInformation dateReceived = new FieldInformation { DisplayName = "Date Received", InternalName = "Date Received", Type = FieldType.Text, Value = DateTime.Now.ToString() };

                    FieldInformation[] myFieldInfoArray = { from, dateReceived, subject, body };

                    if (email.Attachments.Count > 0)
                    {
                        foreach (Attachment attachment in email.Attachments)
                        {
                            string copySource = attachment.FileName;
                            string[] copyDest = { Config["SharePointSiteUrl"] + Config["SharePointLibraryName"] + attachment.FileName };

                            try
                            {
                                byte[] myByteArray = attachment.Content;

                                uint myCopyUint = spDocumentCopyService.CopyIntoItems(copySource, copyDest, myFieldInfoArray, myByteArray, out myCopyResultArray);

                                if (myCopyUint != 0)
                                {
                                    Logger logger = LogManager.GetCurrentClassLogger();
                                    logger.Log(LogLevel.Error, String.Concat(myCopyResultArray));
                                }
                            }
                            catch (Exception e)
                            {
                                Logger logger = LogManager.GetCurrentClassLogger();
                                logger.Log(LogLevel.Error, "Exception occurred when loading mail into SharePoint library", e);
                            }
                        }
                    }
                    else // An email without attachments:
                    {
                        try
                        {
                            string[] copyDest = { Config["SharePointSiteUrl"] + Config["SharePointLibraryName"] + GetPrependedDateTime() + "No_Attachment" };
                            byte[] myByteArray = { byte.MinValue };

                            uint myCopyUint = spDocumentCopyService.CopyIntoItems("nofile", copyDest, myFieldInfoArray, myByteArray, out myCopyResultArray);

                            if (myCopyUint != 0)
                            {
                                Logger logger = LogManager.GetCurrentClassLogger();
                                logger.Log(LogLevel.Error, String.Concat(myCopyResultArray));
                            }
                        }
                        catch (Exception e)
                        {
                            Logger logger = LogManager.GetCurrentClassLogger();
                            logger.Log(LogLevel.Error, "Exception occurred when loading mail into SharePoint library", e);
                        }
                    }
                }
            }
            TimeLastLoaded = DateTime.Now;
        }