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);
                    }
                }
            }
        }
        private string GetFilePropertyValue(string propertyName, FieldInformation[] basicFieldInfoArray)
        {
            string value = string.Empty;

            try
            {
                IEnumerable<string> fieldPropertyValue = (from fieldInfo in basicFieldInfoArray where fieldInfo.DisplayName.Equals(propertyName) select fieldInfo.Value);
                if (fieldPropertyValue != null && fieldPropertyValue.First() != null)
                {
                    value = fieldPropertyValue.First();
                }
            }
            catch (Exception e)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Log(LogLevel.Error, "GetFilePropertyValue: Exception occurred when trying to get document type or subtype (most likely)", e);
            }

            return value;
        }
Esempio n. 3
0
 public uint GetItem(string Url, out FieldInformation[] Fields, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] out byte[] Stream) {
     object[] results = this.Invoke("GetItem", new object[] {
                 Url});
     Fields = ((FieldInformation[])(results[1]));
     Stream = ((byte[])(results[2]));
     return ((uint)(results[0]));
 }
Esempio n. 4
0
 /// <remarks/>
 public void CopyIntoItemsAsync(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, byte[] Stream, object userState) {
     if ((this.CopyIntoItemsOperationCompleted == null)) {
         this.CopyIntoItemsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCopyIntoItemsOperationCompleted);
     }
     this.InvokeAsync("CopyIntoItems", new object[] {
                 SourceUrl,
                 DestinationUrls,
                 Fields,
                 Stream}, this.CopyIntoItemsOperationCompleted, userState);
 }
Esempio n. 5
0
 /// <remarks/>
 public void CopyIntoItemsAsync(string SourceUrl, string[] DestinationUrls, FieldInformation[] Fields, byte[] Stream) {
     this.CopyIntoItemsAsync(SourceUrl, DestinationUrls, Fields, Stream, null);
 }
Esempio n. 6
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]));
 }
        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;
        }