Ejemplo n.º 1
0
        /// <summary>
        /// Inserts the details as HTML.
        /// </summary>
        /// <param name="attachments">The attachments.</param>
        /// <param name="range">The range.</param>
        /// <param name="positionBeforeAdd">The position before add.</param>
        /// <param name="mailItem">The mail item.</param>
        /// <param name="numberFailedAttachments">The number failed attachments.</param>
        /// <returns></returns>
        private int InsertDetailsAsHtml(List <Utilities.PreferredFileInformation> attachments, Word.Range range, int positionBeforeAdd, OfficeOutlook.MailItem mailItem, out int numberFailedAttachments)
        {
            numberFailedAttachments = 0;
            if (this.insertAsCopy)
            {
                for (int n = 0; n < attachments.Count; n++)
                {
                    Utilities.PreferredFileInformation fileInfo = attachments[n];
                    try
                    {
                        mailItem.Attachments.Add(fileInfo.LocalPath, OfficeOutlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        if (ex.Message.ToUpperInvariant() == attachmentWarning.ToUpperInvariant())
                        {
                            numberFailedAttachments++;
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }

            if (this.insertAsLink)
            {
                // Adding the attachments resets the Range to the top of the document, so we need to move the range
                // to were the user's cursor was when they started the process
                range.SetRange(positionBeforeAdd, positionBeforeAdd);

                for (int n = 0; n < attachments.Count; n++)
                {
                    Utilities.PreferredFileInformation fileInfo = attachments[n];
                    Word.Hyperlink hyperlink = range.Hyperlinks.Add(range, fileInfo.Url, Type.Missing, Type.Missing, fileInfo.ToString());
                    range.SetRange(hyperlink.Range.End, hyperlink.Range.End);
                    range.InsertAfter(Environment.NewLine);
                    range.SetRange(range.End, range.End);
                }

                return(range.End);
            }

            return(0);
        }
Ejemplo n.º 2
0
        private void InsertDetailsAsDefault(List <Utilities.PreferredFileInformation> attachments, Word.Range range, OfficeOutlook.MailItem mailItem, out int numberFailedAttachments)
        {
            numberFailedAttachments = 0;
            for (int n = 0; n < attachments.Count; n++)
            {
                Utilities.PreferredFileInformation fileInfo = attachments[n];

                int endIndex = range.End;

                if (this.insertAsCopy)
                {
                    try
                    {
                        mailItem.Attachments.Add(fileInfo.LocalPath, OfficeOutlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }
                    catch (System.Runtime.InteropServices.COMException ex)
                    {
                        if (ex.Message.ToUpperInvariant() == attachmentWarning.ToUpperInvariant())
                        {
                            numberFailedAttachments++;
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                if (this.insertAsLink)
                {
                    range.SetRange(endIndex, endIndex);
                    range.InsertAfter(fileInfo.Url);
                    range.InsertAfter(Environment.NewLine);
                }
            }
        }