本文整理汇总了C#中System.Net.Mime.ContentType类的典型用法代码示例。如果您正苦于以下问题:C# ContentType类的具体用法?C# ContentType怎么用?C# ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentType类属于System.Net.Mime命名空间,在下文中一共展示了ContentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SupportsContentType
public static bool SupportsContentType(ContentType contentType)
{
for(int i = 0; i != SupportedContentTypes.Length; ++i)
if(SupportedContentTypes[i].Equals(contentType.MediaType))
return true;
return false;
}
示例2: Index
public ActionResult Index()
{
var outParam = new SqlParameter
{
ParameterName = "@result",
Direction = ParameterDirection.Output,
SqlDbType = SqlDbType.Int
};
List<Boolean> _BUEvent = db.Database.SqlQuery<Boolean>("sp_InsertIntoBuEventLog @result OUT", outParam).ToList();
using (TransactionScope transaction = new TransactionScope())
{
bool result = _BUEvent.FirstOrDefault();
if (result)
{
var _vwSendEmail = (db.vwSendEmails.Where(a => a.CREATEDDATE == CurrentDate).Select(a => new { a.KDKC, a.email, a.NMKC,a.TAHUN,a.BULAN,a.MINGGU })).Distinct();
int count = 0;
foreach(var sending in _vwSendEmail)
{
MemoryStream memory = new MemoryStream();
PdfDocument document = new PdfDocument() { Url = string.Format("http://localhost:1815/AutoMail/PreviewPage?kdkc={0}", sending.KDKC) };
PdfOutput output = new PdfOutput() { OutputStream = memory };
PdfConvert.ConvertHtmlToPdf(document, output);
memory.Position = 0;
var SubjectName = string.Format("Reminder Masa Habis PKS Badan Usaha T{0} B{1} M{2}", sending.TAHUN, sending.BULAN, sending.MINGGU);
var attchName = string.Format("ReminderMasaHabisPKSBadanUsahaT{0}B{1}M{2}", sending.TAHUN, sending.BULAN, sending.MINGGU);
ContentType ct = new ContentType(MediaTypeNames.Application.Pdf);
Attachment data = new Attachment(memory, ct);
data.Name = attchName;
MailMessage message = new MailMessage();
message.To.Add(new MailAddress(sending.email));
message.From = new MailAddress("[email protected]", "Legal-InHealth Reminder ");
message.Subject = SubjectName;
message.Attachments.Add(data);
message.Body = sending.NMKC;
SmtpClient client = new SmtpClient();
try
{
client.Send(message);
}
catch (Exception ex)
{
ViewData["SendingException"] = string.Format("Exception caught in SendErrorLog: {0}",ex.ToString());
return View("ErrorSending", ViewData["SendingException"]);
}
data.Dispose();
// Close the log file.
memory.Close();
count += 1;
}
}
transaction.Complete();
}
return View();
}
示例3: XmlSerializationResult
public XmlSerializationResult(object model,
string contentType)
{
if (null == model)
{
throw new ArgumentNullException("model");
}
if (null == contentType)
{
throw new ArgumentNullException("contentType");
}
if (0 == contentType.Length)
{
throw new ArgumentOutOfRangeException("contentType");
}
ContentEncoding = Encoding.UTF8;
ContentType = new ContentType(contentType).MediaType;
var xml = model.XmlSerialize() as XmlDocument;
if (null == xml)
{
return;
}
xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.PreserveWhitespace = false;
Content = xml.OuterXml;
}
示例4: Deserialize
public object Deserialize(ControllerContext controllerContext, ModelBindingContext bindingContext, ContentType requestFormat)
{
string input = new StreamReader(controllerContext.HttpContext.Request.InputStream).ReadToEnd();
MethodInfo deserialize = typeof(JavaScriptSerializer).GetMethod("Deserialize", new Type[] { typeof(string) });
MethodInfo deserializeForType = deserialize.MakeGenericMethod(bindingContext.ModelType);
return deserializeForType.Invoke(new JavaScriptSerializer(), new object[] { input });
}
示例5: SignedEntity
/// <summary>
/// Creates an entity from the <paramref name="parts"/> of which the first part must be the content and the second
/// part the signature..
/// </summary>
/// <param name="contentType">The content type header for the new entity.</param>
/// <param name="parts">The body parts, which must consist of two parts, of which the first must be the content and the second part the signature</param>
public SignedEntity(ContentType contentType, IEnumerable<MimeEntity> parts)
: base(contentType)
{
if (parts == null)
{
throw new ArgumentNullException("parts");
}
int count = 0;
foreach(MimeEntity part in parts)
{
switch(count)
{
default:
throw new SignatureException(SignatureError.InvalidSignedEntity);
case 0:
Content = part;
break;
case 1:
Signature = part;
break;
}
++count;
}
}
示例6: CreateAttachmentFromString
public static Attachment CreateAttachmentFromString(string content, ContentType contentType)
{
Attachment attachment = new Attachment();
attachment.SetContentFromString(content, contentType);
attachment.Name = contentType.Name;
return attachment;
}
示例7: Main
static void Main(string[] args)
{
HttpWebRequest request = WebRequest.Create("https://www.baidu.com/") as HttpWebRequest;
request.Method = "GET";
request.AddRange("bytes", 0, 1000);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
ContentType content = new ContentType();
foreach (string header in response.Headers)
{
Console.WriteLine("{0}:{1}", header, response.Headers[header]);
}
var stream = response.GetResponseStream();
//int count = (int)response.ContentLength;
//byte[] bytes = new byte[count];
//stream.Read(bytes, 0, count);
//var str = Encoding.UTF8.GetString(bytes);
using (StreamReader reader = new StreamReader(stream))
{
StreamWriter writer = new StreamWriter("index.html");
string line;
while ((line = reader.ReadLine()) != null)
{
writer.WriteLine(line);
}
}
Console.WriteLine("ok");
Console.ReadKey();
}
示例8: MessageHeader
/// <summary>
/// Parses a <see cref="NameValueCollection"/> to a MessageHeader
/// </summary>
/// <param name="headers">The collection that should be traversed and parsed</param>
/// <returns>A valid MessageHeader object</returns>
/// <exception cref="ArgumentNullException">If <paramref name="headers"/> is <see langword="null"/></exception>
internal MessageHeader(NameValueCollection headers)
{
if (headers == null)
throw new ArgumentNullException("headers");
// Create empty lists as defaults. We do not like null values
// List with an initial capacity set to zero will be replaced
// when a corrosponding header is found
To = new List<RfcMailAddress>(0);
Cc = new List<RfcMailAddress>(0);
Bcc = new List<RfcMailAddress>(0);
Received = new List<Received>();
Keywords = new List<string>();
InReplyTo = new List<string>(0);
References = new List<string>(0);
DispositionNotificationTo = new List<RfcMailAddress>();
UnknownHeaders = new NameValueCollection();
// Default importancetype is Normal (assumed if not set)
Importance = MailPriority.Normal;
// 7BIT is the default ContentTransferEncoding (assumed if not set)
ContentTransferEncoding = ContentTransferEncoding.SevenBit;
// text/plain; charset=us-ascii is the default ContentType
ContentType = new ContentType("text/plain; charset=us-ascii");
// Now parse the actual headers
ParseHeaders(headers);
}
示例9: Validate
public async Task<ValidateResult> Validate(HttpRequestBase request, HttpResponseBase response)
{
request.ThrowIfNull("request");
response.ThrowIfNull("response");
if (!String.IsNullOrEmpty(request.ContentType))
{
try
{
var contentType = new ContentType(request.ContentType);
if (String.Equals(contentType.MediaType, "application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase) || String.Equals(contentType.MediaType, "multipart/form-data", StringComparison.OrdinalIgnoreCase))
{
ValidationResult validationResult = await _antiCsrfNonceValidator.ValidateAsync(request);
ResponseResult responseResult = await _antiCsrfResponseGenerator.GetResponseAsync(validationResult);
if (responseResult.ResultType == ResponseResultType.ResponseGenerated)
{
return ValidateResult.ResponseGenerated(responseResult.Response);
}
}
}
catch (FormatException)
{
}
}
await _antiCsrfCookieManager.ConfigureCookieAsync(request, response);
return ValidateResult.RequestValidated();
}
示例10: MailAttachment
public MailAttachment(ContentType contentType, string fileName, MemoryStream fileStream)
{
this._ContentType = contentType;
this._FileStream = fileStream;
this._Name = fileName;
this._ByteArray = CommonHelper.StreamToByteArray(fileStream);
}
示例11: NewApplication
public ActionResult NewApplication(TestInfo testInfo)
{
string response = "";
if (ModelState.IsValid)
{
response = new RegisterRepository().RegisterTest(testInfo);
MailMessage message = new MailMessage();
string username = "[email protected]";
string password = "1ndustries";
string receiverEmail = testInfo.StudentInfo.AddressInfo.Email;
ContentType mimeType = new ContentType("text/html");
AlternateView alternate = AlternateView.CreateAlternateViewFromString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <html><head><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\"></head><body><b>Dear " + testInfo.StudentInfo.FirstName + testInfo.StudentInfo.LastName + "</b>, <br /><br /><br />Greetings from IELTS !!! <br/><br/><br/> Your registration was successful. Thank You for registering IELTS Examination. <br/> <br/> <br/> Please see below the registration details <br/> <b> Your Receipt Number :</b> " + testInfo.ReceiptNumber + ".<br /><b> Registered Date Time :</b> " + testInfo.CreatedDate.ToString() + "<br /><br /> <b>Note: </b> Receipt Number and Passport or National Identity Card is mandatory to check your test results. <br /><br /><br /> Thank You,<br/><br/><br/> IELTS Admin</body></html>.", mimeType);
message.From = new MailAddress(username);
message.To.Add(receiverEmail);
message.Subject = "IELTS Registration - Congrats, " + testInfo.StudentInfo.FirstName + " " + testInfo.StudentInfo.LastName + "!";
//message.Body = "<html><head></head><body><b>Dear " + testInfo.StudentInfo.FirstName + testInfo.StudentInfo.LastName + "</b>, <br /><br /><br />Greetings from IELTS !!! <br/> Your registration was successful. Thank You for registering IELTS Examination. <br/> Please see below the registration details <br/> <dd /><b>Your Receipt Number :</b> " + testInfo.ReceiptNumber + ".<br /><dd /><b>Registered Date Time :</b> "+testInfo.CreatedDate.ToString()+"<br /><br /> <b>Note: </b> Receipt Number is mandatory to check your test results. <br /><br /><br /> Thank You, IELTS Admin</body></html>.";
message.AlternateViews.Add(alternate);
message.IsBodyHtml = true;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(message);
RedirectToAction("SubmitApplicationForm");
}
return View(testInfo);
}
示例12: HTTPHeader
public HTTPHeader()
{
Headers = new NameValueCollection();
ContentType = new System.Net.Mime.ContentType(MediaTypeNames.Text.Html);
CacheControl = "no-cache";
_ContentLength = 0;
}
示例13: ButtonSendClick
private void ButtonSendClick(object sender, RoutedEventArgs e)
{
var teacherChoice = new TeacherChoice
{
Alternatives = GridDays.Children
.OfType<RadioButton>()
.Where(l => l.IsChecked.HasValue)
.Select(l => l.DataContext)
.Cast<Alternative>().ToList(),
Email = Email,
Name = FullName,
};
Options.IsEnabled = false;
busyIndicator.IsBusy = true;
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("[email protected]", "admin123."),
EnableSsl = true,
};
var contentType = new ContentType("text/xml") { Name = "teacherChoice.xml" };
var xmlAttachment = Attachment.CreateAttachmentFromString(teacherChoice.Serialize(), contentType);
var mail = new MailMessage("[email protected]", "[email protected]")
{
Subject = "Teste",
};
mail.Attachments.Add(xmlAttachment);
client.SendCompleted += ClientSendCompleted;
client.SendAsync(mail, Token);
}
示例14: AttachmentBase
protected AttachmentBase (string fileName)
{
if (fileName == null)
throw new ArgumentNullException ();
contentStream = File.OpenRead (fileName);
contentType = new ContentType (MimeTypes.GetMimeType (fileName));
}
示例15: SendInstantMessageAsync
public static Task<SendInstantMessageResult> SendInstantMessageAsync(this
InstantMessagingFlow flow, ContentType contentType,
byte[] body)
{
return Task<SendInstantMessageResult>.Factory.FromAsync(flow.BeginSendInstantMessage,
flow.EndSendInstantMessage, contentType, body, null);
}