当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Outlook.SaveAsFile方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Outlook.SaveAsFile方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Outlook.SaveAsFile方法的具体用法?C# Microsoft.Office.Interop.Outlook.SaveAsFile怎么用?C# Microsoft.Office.Interop.Outlook.SaveAsFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Outlook的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Outlook.SaveAsFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addContentFile

        public bool addContentFile(Outlook.Attachment attachment, string docRef)
        {
            // Extraction et copie en local du message Outlook au format MSG
            string filename = attachment.FileName;
            string fsFilename = repTemp + AddSlashes(filename);
            attachment.SaveAsFile(fsFilename);

            // Lancement de la commande REST d'ajout du fichier principal au document courant
            StringBuilder url = new StringBuilder(nuxeo + "restAPI/default/");
            url.Append(docRef);
            url.Append("/");
            url.Append(filename);
            url.Append("/uploadFile");
            HttpWebRequest request = WebRequest.Create(url.ToString()) as HttpWebRequest;

            request.Credentials = new NetworkCredential(login, mdp);
            request.Method = "POST";
            request.ContentType = "application/msoutlook";

            byte[] buff = null;
            FileStream fs = new FileStream(fsFilename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            long numBytes = new FileInfo(fsFilename).Length;
            buff = br.ReadBytes((int)numBytes);
            br.Close();

            try
            {
                using (Stream postStream = request.GetRequestStream())
                {
                    postStream.Write(buff, 0, buff.Length);
                }
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string resultXml = reader.ReadToEnd();
                }

                File.Delete(fsFilename);
                return true;
            }
            catch (Exception e)
            {

                FormError bob = new FormError(e.ToString(), "Le plugin a rencontré un problème lors de l'upload du message."
                + System.Environment.NewLine + "Veuillez réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Upload fail :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }

                return false;
            }
        }
开发者ID:ldoguin,项目名称:NuxeoOutlookAddin,代码行数:57,代码来源:NuxeoAttachWrapper.cs

示例2: HandlePgpMime

		void HandlePgpMime(Outlook.MailItem mailItem, Outlook.Attachment encryptedMime,
			Outlook.Attachment sigMime, string sigHash = "sha1")
		{
			logger.Trace("> HandlePgpMime");
			CryptoContext Context = null;

			byte[] cyphertext = null;
			byte[] clearbytes = null;
			var cleartext = mailItem.Body;

			// 1. Decrypt attachement

			if (encryptedMime != null)
			{
				logger.Trace("Decrypting cypher text.");

				var tempfile = Path.GetTempFileName();
				encryptedMime.SaveAsFile(tempfile);
				cyphertext = File.ReadAllBytes(tempfile);
				File.Delete(tempfile);

				clearbytes = DecryptAndVerify(mailItem.To, cyphertext, out Context);
				if (clearbytes == null)
					return;

				cleartext = this._encoding.GetString(clearbytes);
			}

			// 2. Verify signature

			if (sigMime != null)
			{
				Context = new CryptoContext(PasswordCallback, _settings.Cipher, _settings.Digest);
				var Crypto = new PgpCrypto(Context);
				var mailType = mailItem.BodyFormat;

				try
				{
					logger.Trace("Verify detached signature");

					var tempfile = Path.GetTempFileName();
					sigMime.SaveAsFile(tempfile);
					var detachedsig = File.ReadAllText(tempfile);
					File.Delete(tempfile);

					// Build up a clearsignature format for validation
					// the rules for are the same with the addition of two heaer fields.
					// Ultimately we need to get these fields out of email itself.

					// NOTE: encoding could be uppercase or lowercase. Try both.
					//       this is definetly hacky :/

					var encoding = GetEncodingFromMail(mailItem);
					var body = string.Empty;

					// Try two different methods to get the mime body
					try
					{
						body = encoding.GetString(
							(byte[])mailItem.PropertyAccessor.GetProperty(
								"http://schemas.microsoft.com/mapi/string/{4E3A7680-B77A-11D0-9DA5-00C04FD65685}/Internet Charset Body/0x00000102"));
					}
					catch (Exception)
					{
						body = (string)mailItem.PropertyAccessor.GetProperty(
								"http://schemas.microsoft.com/mapi/proptag/0x1000001F"); // PR_BODY
					}

					var clearsigUpper = new StringBuilder();

					clearsigUpper.Append(string.Format("-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: {0}\r\nCharset: {1}\r\n\r\n", sigHash, encoding.BodyName.ToUpper()));
					clearsigUpper.Append("Content-Type: text/plain; charset=");
					clearsigUpper.Append(encoding.BodyName.ToUpper());
					clearsigUpper.Append("\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n");

					clearsigUpper.Append(PgpClearDashEscapeAndQuoteEncode(body));

					clearsigUpper.Append("\r\n");
					clearsigUpper.Append(detachedsig);

					var clearsigLower = new StringBuilder(clearsigUpper.Length);

					clearsigLower.Append(string.Format("-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: {0}\r\nCharset: {1}\r\n\r\n", sigHash, encoding.BodyName.ToUpper()));
					clearsigLower.Append("Content-Type: text/plain; charset=");
					clearsigLower.Append(encoding.BodyName.ToLower());
					clearsigLower.Append("\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n");

					clearsigLower.Append(PgpClearDashEscapeAndQuoteEncode(body));

					clearsigLower.Append("\r\n");
					clearsigLower.Append(detachedsig);

					logger.Trace(clearsigUpper.ToString());

					if (Crypto.VerifyClear(_encoding.GetBytes(clearsigUpper.ToString())) || Crypto.VerifyClear(_encoding.GetBytes(clearsigLower.ToString())))
					{
						Context = Crypto.Context;

						var message = "** " + string.Format(Localized.MsgValidSig,
							Context.SignedByUserId, Context.SignedByKeyId) + "\n\n";
//.........这里部分代码省略.........
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:101,代码来源:OutlookPrivacyPlugin.cs

示例3: Base64Encode

        public byte[] Base64Encode(Outlook.Attachment objMailAttachment, Outlook.MailItem objMail)
        {
            byte[] strRet = null;
            if (objMailAttachment != null)
            {
                if (System.IO.Directory.Exists(Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath") == false)
                {
                    string strPath = Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath";
                    System.IO.Directory.CreateDirectory(strPath);
                }
                try
                {
                    objMailAttachment.SaveAsFile(Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath\\" + objMailAttachment.FileName);
                    strRet = System.IO.File.ReadAllBytes(Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath\\" + objMailAttachment.FileName);
                }
                catch (COMException ex)
                {
                    try
                    {
                        string strLog;
                        strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n";
                        strLog += "AddInModule.Base64Encode method COM Exception:" + "\n";
                        strLog += "Message:" + ex.Message + "\n";
                        strLog += "Source:" + ex.Source + "\n";
                        strLog += "StackTrace:" + ex.StackTrace + "\n";
                        strLog += "Data:" + ex.Data.ToString() + "\n";
                        strLog += "HResult:" + ex.HResult.ToString() + "\n";
                        strLog += "Inputs:" + "\n";
                        strLog += "Data:" + objMailAttachment.DisplayName + "\n";
                        strLog += "-------------------------------------------------------------------------" + "\n";
                        clsSuiteCRMHelper.WriteLog(strLog);
                        ex.Data.Clear();
                        string strName = Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath\\" + DateTime.Now.ToString("MMddyyyyHHmmssfff") + ".html";
                        objMail.SaveAs(strName, Microsoft.Office.Interop.Outlook.OlSaveAsType.olHTML);
                        foreach (string strFileName in System.IO.Directory.GetFiles(strName.Replace(".html", "_files")))
                        {
                            if (strFileName.EndsWith("\\" + objMailAttachment.DisplayName))
                            {
                                strRet = System.IO.File.ReadAllBytes(strFileName);
                                break;
                            }
                        }
                    }
                    catch (Exception ex1)
                    {
                        string strLog;
                        strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n";
                        strLog += "AddInModule.Base64Encode method General Exception:" + "\n";
                        strLog += "Message:" + ex.Message + "\n";
                        strLog += "Source:" + ex.Source + "\n";
                        strLog += "StackTrace:" + ex.StackTrace + "\n";
                        strLog += "Data:" + ex.Data.ToString() + "\n";
                        strLog += "HResult:" + ex.HResult.ToString() + "\n";
                        strLog += "Inputs:" + "\n";
                        strLog += "Data:" + objMailAttachment.DisplayName + "\n";
                        strLog += "-------------------------------------------------------------------------" + "\n";
                        clsSuiteCRMHelper.WriteLog(strLog);
                        ex1.Data.Clear();
                    }
                }
                finally
                {
                    if (System.IO.Directory.Exists(Environment.SpecialFolder.MyDocuments.ToString() + "\\SuiteCRMTempAttachmentPath") == true)
                    {
                        System.IO.Directory.Delete(Environment.SpecialFolder.MyDocuments.ToString(), true);
                    }
                }
            }

            return strRet;
        }
开发者ID:christoyer,项目名称:SuiteCRM-Outlook-Plugin,代码行数:71,代码来源:ThisAddIn.cs


注:本文中的Microsoft.Office.Interop.Outlook.SaveAsFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。