本文整理汇总了C#中Microsoft.SaveAsFile方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.SaveAsFile方法的具体用法?C# Microsoft.SaveAsFile怎么用?C# Microsoft.SaveAsFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft
的用法示例。
在下文中一共展示了Microsoft.SaveAsFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtectAttachment
public ProtectAttachment(Microsoft.Office.Interop.Outlook.Attachment attachment)
: this()
{
// 17470 [WS 8.0] Protect files is not enabled when .msg with no subject is attached through Right click->send To->Mail Recipient.ZenQ
Name = attachment.DisplayName ?? "";
var filename = string.Empty;
filename = attachment.FileName.ToLower() == ".msg"
? Guid.NewGuid().ToString() + ".msg"
: attachment.FileName;
// --
Index = attachment.Index.ToString(CultureInfo.InvariantCulture);
var wsAttachment = attachment as WsAttachment;
if (wsAttachment != null)
{
Id = wsAttachment.Id.ToString();
RecordKey = wsAttachment.RecordKey;
}
_lcofm = new LocalCopyOfFileManager();
filename = _lcofm.GetLocalCopyOfFileTarget(filename);
attachment.SaveAsFile(filename);
var lah = new LargeAttachmentHelper(filename);
if (lah.IsLargeAttachment)
{
LargeAttachmentFileName = filename;
var tempfile = _lcofm.GetLocalCopyOfFileTarget(Path.GetFileName(lah.ActualPath));
System.IO.File.Copy(lah.ActualPath, tempfile, true);
filename = tempfile;
Name = Path.GetFileName(filename);
}
File = FcsFileFactory.Create(filename, Name);
Position = attachment.Position;
FileName = filename;
}
示例2: HandlePgpMime
void HandlePgpMime(Outlook.MailItem mailItem, Microsoft.Office.Interop.Outlook.Attachment encryptedMime,
Microsoft.Office.Interop.Outlook.Attachment sigMime, string sigHash = "sha1")
{
logger.Trace("> HandlePgpMime");
CryptoContext Context = null;
string sig = null;
byte[] cyphertext = null;
string 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);
var 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(Passphrase);
var Crypto = new PgpCrypto(Context);
Outlook.OlBodyFormat 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.
var encoding = GetEncodingFromMail(mailItem);
var clearsig = string.Format("-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: {0}\r\n\r\n", sigHash);
//clearsig += "Content-Type: text/plain; charset=ISO-8859-1\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n";
clearsig += "Content-Type: text/plain; charset=" +
encoding.BodyName.ToUpper()+
"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n";
clearsig += PgpClearDashEscapeAndQuoteEncode(
encoding.GetString(
(byte[])mailItem.PropertyAccessor.GetProperty(
"http://schemas.microsoft.com/mapi/string/{4E3A7680-B77A-11D0-9DA5-00C04FD65685}/Internet Charset Body/0x00000102")));
clearsig += "\r\n"+detachedsig;
logger.Trace(clearsig);
if (Crypto.VerifyClear(_encoding.GetBytes(clearsig)))
{
Context = Crypto.Context;
var message = "** Valid signature from \"" + Context.SignedByUserId +
"\" with KeyId " + Context.SignedByKeyId + ".\n\n";
if (mailType == Outlook.OlBodyFormat.olFormatPlain)
{
mailItem.Body = message + mailItem.Body;
}
}
else
{
Context = Crypto.Context;
var message = "** Invalid signature from \"" + Context.SignedByUserId +
"\" with KeyId " + Context.SignedByKeyId + ".\n\n";
if (mailType == Outlook.OlBodyFormat.olFormatPlain)
{
mailItem.Body = message + mailItem.Body;
}
}
}
catch (PublicKeyNotFoundException ex)
{
logger.Debug(ex.ToString());
Context = Crypto.Context;
var message = "** Unable to verify signature, missing public key.\n\n";
if (mailType == Outlook.OlBodyFormat.olFormatPlain)
//.........这里部分代码省略.........
示例3: HandlePgpMime
void HandlePgpMime(Outlook.MailItem mailItem, Microsoft.Office.Interop.Outlook.Attachment encryptedMime,
Microsoft.Office.Interop.Outlook.Attachment sigMime, string sigHash = "sha1")
{
logger.Trace("> HandlePgpMime");
CryptoContext Context = null;
byte[] cyphertext = null;
byte[] clearbytes = null;
string 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);
Outlook.OlBodyFormat 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 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(
encoding.GetString(
(byte[])mailItem.PropertyAccessor.GetProperty(
"http://schemas.microsoft.com/mapi/string/{4E3A7680-B77A-11D0-9DA5-00C04FD65685}/Internet Charset Body/0x00000102"))));
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(
encoding.GetString(
(byte[])mailItem.PropertyAccessor.GetProperty(
"http://schemas.microsoft.com/mapi/string/{4E3A7680-B77A-11D0-9DA5-00C04FD65685}/Internet Charset Body/0x00000102"))));
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";
if (mailType == Outlook.OlBodyFormat.olFormatPlain)
mailItem.Body = message + mailItem.Body;
else
mailItem.HTMLBody = AddMessageToHtmlBody(mailItem.HTMLBody, message);
}
else
{
//.........这里部分代码省略.........
示例4: attachFile
/* Upload attachments */
public void attachFile(Microsoft.Office.Interop.Outlook.Attachment attachment, string docRef)
{
// Save attachments in local
string fsFilename = repTemp + attachment.FileName;
attachment.SaveAsFile(fsFilename);
EnvoiPJ(attachment.FileName, fsFilename, docRef);
}
示例5: HandlePgpMime
void HandlePgpMime(Outlook.MailItem mailItem, Microsoft.Office.Interop.Outlook.Attachment encryptedMime)
{
// 1. Decrypt attachement
CryptoContext Context;
var tempfile = Path.GetTempFileName();
encryptedMime.SaveAsFile(tempfile);
var encrypteddata = File.ReadAllBytes(tempfile);
var cleardata = DecryptAndVerify(mailItem.To, encrypteddata, out Context);
if (cleardata == null)
return;
// Extract files from MIME data
SharpMessage msg = new SharpMessage(this._encoding.GetString(cleardata));
string body = mailItem.Body;
var DecryptAndVerifyHeaderMessage = "** ";
if (Context.IsEncrypted)
DecryptAndVerifyHeaderMessage += "Message decrypted. ";
if (Context.IsSigned && Context.SignatureValidated)
{
DecryptAndVerifyHeaderMessage += "Valid signature from \"" + Context.SignedByUserId +
"\" with KeyId " + Context.SignedByKeyId;
}
else if (Context.IsSigned)
{
DecryptAndVerifyHeaderMessage += "Invalid signature from \"" + Context.SignedByUserId +
"\" with KeyId " + Context.SignedByKeyId + ".";
}
else
DecryptAndVerifyHeaderMessage += "Message was unsigned.";
DecryptAndVerifyHeaderMessage += "\n\n";
if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatPlain)
{
mailItem.Body = DecryptAndVerifyHeaderMessage + msg.Body;
}
else if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatHTML)
{
if (!msg.Body.TrimStart().ToLower().StartsWith("<html"))
{
body = DecryptAndVerifyHeaderMessage + msg.Body;
body = System.Net.WebUtility.HtmlEncode(body);
body = body.Replace("\n", "<br />");
mailItem.HTMLBody = "<html><head></head><body>" + body + "</body></html>";
}
else
{
// Find <body> tag and insert our message.
var matches = Regex.Match(msg.Body, @"(<body[^<]*>)", RegexOptions.IgnoreCase);
if (matches.Success)
{
var bodyTag = matches.Groups[1].Value;
// Insert decryption message.
mailItem.HTMLBody = msg.Body.Replace(
bodyTag,
bodyTag + DecryptAndVerifyHeaderMessage.Replace("\n", "<br />"));
}
else
mailItem.HTMLBody = msg.Body;
}
}
else
{
// May cause mail item not to open correctly
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
mailItem.Body = msg.Body;
}
foreach (SharpAttachment mimeAttachment in msg.Attachments)
{
mimeAttachment.Stream.Position = 0;
var fileName = mimeAttachment.Name;
var tempFile = Path.Combine(Path.GetTempPath(), fileName);
using (FileStream fout = File.OpenWrite(tempFile))
{
mimeAttachment.Stream.CopyTo(fout);
}
mailItem.Attachments.Add(tempFile, Outlook.OlAttachmentType.olByValue, 1, fileName);
}
//mailItem.Save();
}