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


C# Mime.ContentType类代码示例

本文整理汇总了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;
 }
开发者ID:drunkcod,项目名称:Xlnt.Stuff,代码行数:7,代码来源:XmlResult.cs

示例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();
        }
开发者ID:kacrut,项目名称:Legal,代码行数:60,代码来源:AutoMailController.cs

示例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;
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:32,代码来源:XmlSerializationResult.cs

示例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 });
 }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:7,代码来源:JavaScriptSerializerFormatHandler.cs

示例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;
            }
        }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:34,代码来源:SignedEntity.cs

示例6: CreateAttachmentFromString

 public static Attachment CreateAttachmentFromString(string content, ContentType contentType)
 {
     Attachment attachment = new Attachment();
     attachment.SetContentFromString(content, contentType);
     attachment.Name = contentType.Name;
     return attachment;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Attachment.cs

示例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();
        }
开发者ID:youtao,项目名称:WebAPI-Learn,代码行数:30,代码来源:Program.cs

示例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);
        }
开发者ID:naingyelin,项目名称:msgreader,代码行数:36,代码来源:MessageHeader.cs

示例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();
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:31,代码来源:AntiCsrfRequestValidator.cs

示例10: MailAttachment

 public MailAttachment(ContentType contentType, string fileName, MemoryStream fileStream)
 {
     this._ContentType = contentType;
     this._FileStream = fileStream;
     this._Name = fileName;
     this._ByteArray = CommonHelper.StreamToByteArray(fileStream);
 }
开发者ID:surifoll,项目名称:git-test,代码行数:7,代码来源:Attachment.cs

示例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>&nbsp;&nbsp;&nbsp;&nbsp;Your Receipt Number  :</b> " + testInfo.ReceiptNumber + ".<br /><b>&nbsp;&nbsp;&nbsp;&nbsp;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);
        }
开发者ID:rodrigodemingo,项目名称:IELTS,代码行数:30,代码来源:RegisterTestController.cs

示例12: HTTPHeader

 public HTTPHeader()
 {
     Headers = new NameValueCollection();
     ContentType = new System.Net.Mime.ContentType(MediaTypeNames.Text.Html);
     CacheControl = "no-cache";
     _ContentLength = 0;
 }
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:HTTPHeader.cs

示例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);
        }
开发者ID:jimyy,项目名称:school-survey-timetabling,代码行数:34,代码来源:MainWindow.xaml.cs

示例14: AttachmentBase

		protected AttachmentBase (string fileName)
		{
			if (fileName == null)
				throw new ArgumentNullException ();
			contentStream = File.OpenRead (fileName);
			contentType = new ContentType (MimeTypes.GetMimeType (fileName));
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:AttachmentBase.cs

示例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);
 }
开发者ID:juancarlosbaezpozos,项目名称:UCMA-IVR-Demo,代码行数:7,代码来源:InstantMessagingFlowMethods.cs


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