本文整理汇总了C#中Attachment类的典型用法代码示例。如果您正苦于以下问题:C# Attachment类的具体用法?C# Attachment怎么用?C# Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attachment类属于命名空间,在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRead
// This is fired when actually retrieving the attachment
public override void OnRead(string key, Attachment attachment)
{
// Get the filename, and make sure its in the returned metadata
var filename = AugmentMetadataWithFilename(key, attachment.Metadata);
// We can't do anything else without a filename
if (filename == null)
return;
// Add a Content-Type header
var contentType = Utils.GetMimeType(filename);
if (!string.IsNullOrEmpty(contentType))
attachment.Metadata["Content-Type"] = contentType;
// Add a Content-Disposition header
// The filename is supposed to be quoted, but it doesn't escape the quotes properly.
// http://issues.hibernatingrhinos.com/issue/RavenDB-824
// This was fixed in 2235. For prior versions, don't send the quotes.
if (Utils.RavenVersion < Version.Parse("2.0.2235.0"))
attachment.Metadata["Content-Disposition"] = string.Format("attachment; filename={0}", filename);
else
attachment.Metadata["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename);
}
示例2: UploadAttach
public static Guid UploadAttach(FileUpload fu)
{
if (!fu.HasFile || fu.FileName.Length == 0)
{
throw new BusinessObjectLogicException("Please select upload file!");
}
string path = null;
try
{
string subDirectory = DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd");
string directory = System.Configuration.ConfigurationManager.AppSettings["File"] + subDirectory;
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
string title = Path.GetFileNameWithoutExtension(fu.FileName);
string ext = Path.GetExtension(fu.FileName);
path = Path.DirectorySeparatorChar + Path.GetRandomFileName() + ext;
fu.SaveAs(directory + path);
Attachment attach = new Attachment(UserHelper.UserName);
attach.Title = title;
attach.Path = subDirectory + path;
new AttachmentBl().AddAttach(attach);
return attach.UID;
}
catch
{
throw new BusinessObjectLogicException("File upload fail!");
}
}
示例3: IsSignatureRtf
private static bool IsSignatureRtf(Attachment attachment)
{
if (attachment.PropertyAccessor.GetProperty(MAPIProxy.MAPIStringDefines.PR_ATTACH_METHOD) == MAPIProxy.MapiDefines.ATTACH_OLE)
{
// Only allow file types we DON'T clean to be signatures.
try
{
if (attachment.DisplayName == "Picture (Device Independent Bitmap)")
return true;
if (FileTypeBridge.GetSupportedFileType(attachment.FileName) == FileType.Unknown)
{
Interop.Logging.Logger.LogInfo(string.Format("Signature {0} on Rtf formatted message", attachment.DisplayName));
return true;
}
}
catch (System.Exception ex)
{
Interop.Logging.Logger.LogDebug("Caught exception: assuming that when the mail format is rtf you are unable access the filename property of embedded images.");
Interop.Logging.Logger.LogDebug(ex);
return true;
}
}
return false;
}
示例4: IsCalendar
public static bool IsCalendar(Attachment attachment)
{
if (Path.HasExtension(attachment.FileName) && Path.GetExtension(attachment.FileName).ToLower() == ".ics")
return true;
string loweredFileName = attachment.FileName.ToLower();
if (loweredFileName == "paycal_uparrow.gif")
return true;
if (loweredFileName == "paycal_line_datepick.gif")
return true;
if (loweredFileName == "paycal_line_outer_thick.gif")
return true;
if (loweredFileName == "paycal_line_outer_thin.gif")
return true;
if (loweredFileName == "paycal_free.gif")
return true;
if (loweredFileName == "paycal_tent.gif")
return true;
if (loweredFileName == "paycal_busy.gif")
return true;
if (loweredFileName == "paycal_oof.gif")
return true;
if (loweredFileName == "paycal_oowh.gif")
return true;
if (loweredFileName == "paycal_workingelsewhere.gif")
return true;
return false;
}
示例5: OpenActualDocumentFromPlaceHolder
public bool OpenActualDocumentFromPlaceHolder(Attachment attachment)
{
try
{
if (attachment.Size > (1024*5))
{
Logger.LogTrace("Returning without doing anything as the file size is > 5k");
return false;
}
using (var lcfm = new LocalCopyOfFileManager())
{
string filename = lcfm.GetLocalCopyOfFileTarget(attachment.FileName);
attachment.SaveAsFile(filename);
Logger.LogTrace("Saving placeholder file to " + filename);
var lah = new LargeAttachmentHelper(filename);
if (lah.IsLargeAttachment)
{
Logger.LogTrace("Opening actual file from" + lah.ActualPath);
var startInfo = new ProcessStartInfo();
startInfo.FileName = lah.ActualPath;
Process.Start(startInfo);
return true;
}
}
return false;
}
catch (Exception ex)
{
Logger.LogError(ex);
throw;
}
}
示例6: OnAttachmentAdd
private void OnAttachmentAdd(Attachment Attachment)
{
if (AttachmentAdd != null)
{
AttachmentAdd(_wsAttachments.Add(Attachment));
}
}
示例7: OnBeforeAttachmentRead
private void OnBeforeAttachmentRead(Attachment Attachment, ref bool Cancel)
{
if (BeforeAttachmentRead != null)
{
// This is needed to ensure that attachments cannot be opened while IP is updating
// the attachments;
if (LockedForUpdating)
{
Cancel = true;
}
using (var attachment = new WsAttachment(Attachment))
{
foreach (WsAttachment wsAttachment in _wsAttachments)
{
if (wsAttachment.RecordKey == attachment.RecordKey && !string.IsNullOrEmpty(wsAttachment.RecordKey))
{
BeforeAttachmentRead(wsAttachment, ref Cancel);
return;
}
}
}
}
else
Marshal.ReleaseComObject(Attachment);
}
示例8: SendReturnParent
private void SendReturnParent(DirectoryInfo dirInfo)
{
Attachment subFile = new Attachment();
subFile.Name = ".";
subFile.IsReturnParent = true;
SendHeader(subFile);
}
示例9: AttachmentBytes
internal static Attachment AttachmentBytes(string filename)
{
Attachment attachment = new Attachment(filename, null, null, null, false);
attachment.Content = System.IO.File.ReadAllBytes(filename);
return attachment;
}
示例10: ThreadMail
void ThreadMail()
{
email = nameInputField.text;
Debug.Log (email);
MailMessage mail = new MailMessage("[email protected]", email);
// MailMessage mail = new MailMessage("[email protected]", email);
if (Application.platform == RuntimePlatform.IPhonePlayer) {
Attachment a = new Attachment (Application.persistentDataPath + "/" + path, MediaTypeNames.Application.Octet);
mail.Attachments.Add (a);
} else {
Attachment a = new Attachment (path, MediaTypeNames.Application.Octet);
mail.Attachments.Add (a);
}
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Host = "w0062da6.kasserver.com";
// client.Host = "smtp.gmail.com";
// client.Port = 25;
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential ("m0399d9f", "3mVEVGT7wKwKDb5X") as ICredentialsByHost;
// client.Credentials = new System.Net.NetworkCredential ("[email protected]", "okaconf2016") as ICredentialsByHost;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
mail.Subject = "OKA Configuration";
mail.Body = "";
client.Send (mail);
// Debug.Log(a);
}
示例11: SendDirectory
private void SendDirectory(DirectoryInfo dirInfo)
{
Attachment subFile = new Attachment();
subFile.Name = dirInfo.Name;
subFile.IsDirectory = true;
SendHeader(subFile);
}
示例12: BtnOKButton_Click
private void BtnOKButton_Click(object sender, EventArgs e)
{
try
{
if (type == DialogType.Edit)
{
byte[] file = File.ReadAllBytes(textBoxAttachmentFilePath.Text);
Upload uploadedFile = RedmineClientForm.redmine.UploadFile(file);
uploadedFile.FileName = Path.GetFileName(textBoxAttachmentFilePath.Text);
uploadedFile.Description = textBoxDescription.Text;
uploadedFile.ContentType = GetMimeType(Path.GetExtension(textBoxAttachmentFilePath.Text));
issue.Uploads = new List<Upload>();
issue.Uploads.Add(uploadedFile);
RedmineClientForm.redmine.UpdateObject<Issue>(issue.Id.ToString(), issue);
}
else
{
NewAttachment = new Attachment
{
ContentUrl = textBoxAttachmentFilePath.Text,
Description = textBoxDescription.Text,
FileName = Path.GetFileName(textBoxAttachmentFilePath.Text),
ContentType = GetMimeType(Path.GetExtension(textBoxAttachmentFilePath.Text)),
FileSize = (int)new FileInfo(textBoxAttachmentFilePath.Text).Length,
Author = new IdentifiableName { Id = RedmineClientForm.Instance.CurrentUser.Id, Name = RedmineClientForm.Instance.CurrentUser.CompleteName() }
};
}
DialogResult = DialogResult.OK;
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(String.Format(Lang.Error_Exception, ex.Message), Lang.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例13: CheckAttachment
void CheckAttachment(Attachment attachment)
{
Assert.Equal("application/x-file", attachment.ContentType);
Assert.Equal(attachmentId, attachment.Id);
Assert.Equal(attachmentDataBuffer.Length, attachment.Length);
Assert.Equal(attachmentDataBuffer, ReadStreamToBuffer(attachment.Syncronously.OpenRead()));
}
示例14: Equals
public virtual bool Equals(Attachment other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return base.Equals(other) && Equals(other.FileName, FileName) && Equals(other.ContentType, ContentType) &&
other.ContentLength == ContentLength;
}
示例15: WsAttachment
public WsAttachment(Attachment attachment, WsAttachments parent)
{
Id = Guid.NewGuid();
_parent = parent;
_attachment = attachment;
InitializeAttachment();
}