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


C# Headers.ContentDispositionHeaderValue类代码示例

本文整理汇总了C#中System.Net.Http.Headers.ContentDispositionHeaderValue的典型用法代码示例。如果您正苦于以下问题:C# ContentDispositionHeaderValue类的具体用法?C# ContentDispositionHeaderValue怎么用?C# ContentDispositionHeaderValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentDispositionHeaderValue类属于System.Net.Http.Headers命名空间,在下文中一共展示了ContentDispositionHeaderValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateContentDisposition

        void UpdateContentDisposition(HttpResponseMessage responseMessage)
        {
            var contentLength = Encoding.UTF8.GetByteCount(_text);
            if(contentLength > WebServerStartup.SizeCapForDownload && _enforceSizeCap)
            {
                string extension = null;
                if(ContentTypes.Json.Equals(_contentType))
                {
                    extension = "json";
                }
                else if(ContentTypes.Xml.Equals(_contentType))
                {
                    extension = "xml";
                }
                if(extension != null)
                {
                    var contentDisposition = new ContentDispositionHeaderValue("attachment");
                    contentDisposition.Parameters.Add(new NameValueHeaderValue("filename", "Output." + extension));

                    responseMessage.Content.Headers.ContentType = ContentTypes.ForceDownload;
                    responseMessage.Content.Headers.ContentDisposition = contentDisposition;
                    responseMessage.Headers.Add("Server", "Dev2 Server");
                }
            }
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:25,代码来源:StringResponseWriter.cs

示例2: ContentDisposition_SetAndGetContentDisposition_MatchExpectations

        public void ContentDisposition_SetAndGetContentDisposition_MatchExpectations()
        {
            ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue("inline");
            Assert.Equal("inline", contentDisposition.DispositionType);

            contentDisposition.DispositionType = "attachment";
            Assert.Equal("attachment", contentDisposition.DispositionType);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:ContentDispositionHeaderValueTest.cs

示例3: ContentDispositionHeaderValue

		protected ContentDispositionHeaderValue (ContentDispositionHeaderValue source)
		{
			if (source == null)
				throw new ArgumentNullException ("source");

			dispositionType = source.dispositionType;
			if (source.parameters != null) {
				foreach (var item in source.parameters)
					Parameters.Add (new NameValueHeaderValue (item));
			}
		}
开发者ID:frje,项目名称:SharpLang,代码行数:11,代码来源:ContentDispositionHeaderValue.cs

示例4: Ctor_ContentDispositionValidFormat_SuccessfullyCreated

 public void Ctor_ContentDispositionValidFormat_SuccessfullyCreated()
 {
     ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue("inline");
     Assert.Equal("inline", contentDisposition.DispositionType);
     Assert.Equal(0, contentDisposition.Parameters.Count);
     Assert.Null(contentDisposition.Name);
     Assert.Null(contentDisposition.FileName);
     Assert.Null(contentDisposition.CreationDate);
     Assert.Null(contentDisposition.ModificationDate);
     Assert.Null(contentDisposition.ReadDate);
     Assert.Null(contentDisposition.Size);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:12,代码来源:ContentDispositionHeaderValueTest.cs

示例5: FileActionResult

 public FileActionResult(
     HttpRequestMessage request,
     MemoryStream content,
     MediaTypeHeaderValue contentType,
     long? contentLength,
     ContentDispositionHeaderValue contentDisposition)
 {
     this.request = request;
     this.content = content;
     this.contentType = contentType;
     this.contentLength = contentLength;
     this.contentDisposition = contentDisposition;
 }
开发者ID:Warrenn,项目名称:Carbon.MVC,代码行数:13,代码来源:FileActionResult.cs

示例6: Equals

		public void Equals ()
		{
			var value = new ContentDispositionHeaderValue ("x");
			Assert.AreEqual (value, new ContentDispositionHeaderValue ("x"), "#1");
			Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("y"), "#2");

			value = new ContentDispositionHeaderValue ("attachment");
			value.Parameters.Add (new NameValueHeaderValue ("size", "66"));

			Assert.AreEqual (value, new ContentDispositionHeaderValue ("attachment") { Size = 66 }, "#3");
			Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("attachment"), "#4");
			Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("attachment") { FileName="g" }, "#5");
		}
开发者ID:carrie901,项目名称:mono,代码行数:13,代码来源:ContentDispositionHeaderValueTest.cs

示例7: Name_SetNameAndValidateObject_ParametersEntryForNameAdded

        public void Name_SetNameAndValidateObject_ParametersEntryForNameAdded()
        {
            ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue("inline");
            contentDisposition.Name = "myname";
            Assert.Equal("myname", contentDisposition.Name);
            Assert.Equal(1, contentDisposition.Parameters.Count);
            Assert.Equal("name", contentDisposition.Parameters.First().Name);

            contentDisposition.Name = null;
            Assert.Null(contentDisposition.Name);
            Assert.Equal(0, contentDisposition.Parameters.Count);
            contentDisposition.Name = null; // It's OK to set it again to null; no exception.
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:13,代码来源:ContentDispositionHeaderValueTest.cs

示例8: AddInternal

        private void AddInternal(HttpContent content, string name, string fileName)
        {
            if (content.Headers.ContentDisposition == null)
            {
                ContentDispositionHeaderValue header = new ContentDispositionHeaderValue(formData);
                header.Name = name;
                header.FileName = fileName;
                header.FileNameStar = fileName;

                content.Headers.ContentDisposition = header;
            }
            base.Add(content);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:MultipartFormDataContent.cs

示例9: Add

        private static void Add(this MultipartFormDataContent form, HttpContent content, object formValues, string name = null, string fileName = null)
        {
            var header = new ContentDispositionHeaderValue("form-data");
            header.Name = name;
            header.FileName = fileName;
            header.FileNameStar = fileName;

            var headerParameters = new HttpRouteValueDictionary(formValues);
            foreach (var parameter in headerParameters)
            {
                header.Parameters.Add(new NameValueHeaderValue(parameter.Key, parameter.Value.ToString()));
            }

            content.Headers.ContentDisposition = header;
            form.Add(content);
        }
开发者ID:PaybackMan,项目名称:Cinder,代码行数:16,代码来源:MultiPartFormContentExtensions.cs

示例10: TryParse

		public static bool TryParse (string input, out ContentDispositionHeaderValue parsedValue)
		{
			parsedValue = null;

			var lexer = new Lexer (input);
			var t = lexer.Scan ();
			if (t.Kind != Token.Type.Token)
				return false;

			List<NameValueHeaderValue> parameters = null;
			var type = lexer.GetStringValue (t);

			t = lexer.Scan ();

			switch (t.Kind) {
			case Token.Type.SeparatorSemicolon:
				if (!NameValueHeaderValue.TryParseParameters (lexer, out parameters, out t) || t != Token.Type.End)
					return false;
				break;
			case Token.Type.End:
				break;
			default:
				return false;
			}

			parsedValue = new ContentDispositionHeaderValue () {
				dispositionType = type,
				parameters = parameters
			};

			return true;
		}
开发者ID:frje,项目名称:SharpLang,代码行数:32,代码来源:ContentDispositionHeaderValue.cs

示例11: Size_InvalidSizes_PropertyFails

        public void Size_InvalidSizes_PropertyFails()
        {
            ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue("inline");

            // Note that uppercase letters are used. Comparison should happen case-insensitive.
            NameValueHeaderValue sizeParameter = new NameValueHeaderValue("SIZE", "-279172874239");
            contentDisposition.Parameters.Add(sizeParameter);
            Assert.Equal(1, contentDisposition.Parameters.Count);
            Assert.Equal("SIZE", contentDisposition.Parameters.First().Name);
            Assert.Null(contentDisposition.Size);

            // Negatives not allowed
            Assert.Throws<ArgumentOutOfRangeException>(() => { contentDisposition.Size = -279172874240; });
            
            Assert.Null(contentDisposition.Size);
            Assert.Equal(1, contentDisposition.Parameters.Count);
            Assert.Equal("SIZE", contentDisposition.Parameters.First().Name);

            contentDisposition.Parameters.Remove(sizeParameter);
            Assert.Null(contentDisposition.Size);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:21,代码来源:ContentDispositionHeaderValueTest.cs

示例12: DownloadByDay

        public HttpResponseMessage DownloadByDay([FromUri] DateTimeInfo dateTime)
        {
            try
            {
                DateTime temp = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day);
                IEnumerable<ChatMessage> q = GlobalStaticVars.StaticCore.GetMessagesFromDate(temp);
                const string messageFmt = @"[{0}] [{1}] {2}:  {3}";
                MemoryStream stream = new MemoryStream();
                StreamWriter writer = new StreamWriter(stream);

                foreach (var message in q)
                {
                    message.MessageType = message.MessageType.ToUpperInvariant();
                    foreach (var teamPair in Teams)
                    {
                        message.MessageType = message.MessageType.Replace(teamPair.Key, teamPair.Value);
                    }

                    foreach (var squadPair in Squads)
                    {
                        message.MessageType = message.MessageType.Replace(squadPair.Key, squadPair.Value);
                    }

                    writer.Write(String.Format(messageFmt, message.MessageTimeStamp, message.MessageType,
                                               message.Speaker,
                                               message.Text) + "\n");
                }
                writer.Flush();
                stream.Position = 0;

                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
                var disposition = new ContentDispositionHeaderValue("attachment");
                disposition.FileName = string.Format("{0}.txt", temp.ToString("yyyyMMdd"));

                result.Content.Headers.ContentDisposition = disposition;

                return result;
            }
            catch (Exception e)
            {
                return new HttpResponseMessage(HttpStatusCode.NoContent);
            }
        }
开发者ID:Pure-Battlefield,项目名称:gswat,代码行数:45,代码来源:ValuesController.cs

示例13: ToString_UseDifferentContentDispositions_AllSerializedCorrectly

        public void ToString_UseDifferentContentDispositions_AllSerializedCorrectly()
        {
            ContentDispositionHeaderValue contentDisposition = new ContentDispositionHeaderValue("inline");
            Assert.Equal("inline", contentDisposition.ToString());

            contentDisposition.Name = "myname";
            Assert.Equal("inline; name=myname", contentDisposition.ToString());

            contentDisposition.FileName = "my File Name";
            Assert.Equal("inline; name=myname; filename=\"my File Name\"", contentDisposition.ToString());

            contentDisposition.CreationDate = new DateTimeOffset(new DateTime(2011, 2, 15, 8, 0, 0, DateTimeKind.Utc));
            Assert.Equal("inline; name=myname; filename=\"my File Name\"; creation-date="
                + "\"Tue, 15 Feb 2011 08:00:00 GMT\"", contentDisposition.ToString());

            contentDisposition.Parameters.Add(new NameValueHeaderValue("custom", "\"custom value\""));
            Assert.Equal("inline; name=myname; filename=\"my File Name\"; creation-date="
                + "\"Tue, 15 Feb 2011 08:00:00 GMT\"; custom=\"custom value\"", contentDisposition.ToString());

            contentDisposition.Name = null;
            Assert.Equal("inline; filename=\"my File Name\"; creation-date="
                + "\"Tue, 15 Feb 2011 08:00:00 GMT\"; custom=\"custom value\"", contentDisposition.ToString());

            contentDisposition.FileNameStar = "File%Name";
            Assert.Equal("inline; filename=\"my File Name\"; creation-date="
                + "\"Tue, 15 Feb 2011 08:00:00 GMT\"; custom=\"custom value\"; filename*=utf-8\'\'File%25Name",
                contentDisposition.ToString());

            contentDisposition.FileName = null;
            Assert.Equal("inline; creation-date=\"Tue, 15 Feb 2011 08:00:00 GMT\"; custom=\"custom value\";"
                + " filename*=utf-8\'\'File%25Name", contentDisposition.ToString());

            contentDisposition.CreationDate = null;
            Assert.Equal("inline; custom=\"custom value\"; filename*=utf-8\'\'File%25Name",
                contentDisposition.ToString());
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:36,代码来源:ContentDispositionHeaderValueTest.cs

示例14: Equals_UseContentDispositionWithAndWithoutParameters_EqualOrNotEqualNoExceptions

        public void Equals_UseContentDispositionWithAndWithoutParameters_EqualOrNotEqualNoExceptions()
        {
            ContentDispositionHeaderValue contentDisposition1 = new ContentDispositionHeaderValue("inline");
            ContentDispositionHeaderValue contentDisposition2 = new ContentDispositionHeaderValue("inline");
            contentDisposition2.Name = "myName";
            ContentDispositionHeaderValue contentDisposition3 = new ContentDispositionHeaderValue("inline");
            contentDisposition3.Parameters.Add(new NameValueHeaderValue("name", "value"));
            ContentDispositionHeaderValue contentDisposition4 = new ContentDispositionHeaderValue("INLINE");
            ContentDispositionHeaderValue contentDisposition5 = new ContentDispositionHeaderValue("INLINE");
            contentDisposition5.Parameters.Add(new NameValueHeaderValue("NAME", "MYNAME"));
            ContentDispositionHeaderValue contentDisposition6 = new ContentDispositionHeaderValue("INLINE");
            contentDisposition6.Parameters.Add(new NameValueHeaderValue("NAME", "MYNAME"));
            contentDisposition6.Parameters.Add(new NameValueHeaderValue("custom", "value"));
            ContentDispositionHeaderValue contentDisposition7 = new ContentDispositionHeaderValue("attachment");

            Assert.False(contentDisposition1.Equals(contentDisposition2)); // "No params vs. name."
            Assert.False(contentDisposition2.Equals(contentDisposition1)); // "name vs. no params."
            Assert.False(contentDisposition1.Equals(null)); // "No params vs. <null>."
            Assert.False(contentDisposition1.Equals(contentDisposition3)); // "No params vs. custom param."
            Assert.False(contentDisposition2.Equals(contentDisposition3)); // "name vs. custom param."
            Assert.True(contentDisposition1.Equals(contentDisposition4)); // "Different casing."
            Assert.True(contentDisposition2.Equals(contentDisposition5)); // "Different casing in name."
            Assert.False(contentDisposition5.Equals(contentDisposition6)); // "name vs. custom param."
            Assert.False(contentDisposition1.Equals(contentDisposition7)); // "inline vs. text/other."
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:25,代码来源:ContentDispositionHeaderValueTest.cs

示例15: GetDispositionTypeLength

        internal static int GetDispositionTypeLength(string input, int startIndex, out object parsedValue)
        {
            Contract.Requires(startIndex >= 0);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return 0;
            }

            // Caller must remove leading whitespaces. If not, we'll return 0.
            string dispositionType = null;
            int dispositionTypeLength = GetDispositionTypeExpressionLength(input, startIndex, out dispositionType);

            if (dispositionTypeLength == 0)
            {
                return 0;
            }

            int current = startIndex + dispositionTypeLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);
            ContentDispositionHeaderValue contentDispositionHeader = new ContentDispositionHeaderValue();
            contentDispositionHeader._dispositionType = dispositionType;

            // If we're not done and we have a parameter delimiter, then we have a list of parameters.
            if ((current < input.Length) && (input[current] == ';'))
            {
                current++; // Skip delimiter.
                int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';',
                    contentDispositionHeader.Parameters);

                if (parameterLength == 0)
                {
                    return 0;
                }

                parsedValue = contentDispositionHeader;
                return current + parameterLength - startIndex;
            }

            // We have a ContentDisposition header without parameters.
            parsedValue = contentDispositionHeader;
            return current - startIndex;
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:45,代码来源:ContentDispositionHeaderValue.cs


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