ContentDispositionHeaderValue Class

System.Net.Http.Headers

Represents a Content-Disposition header value.

Constructors

Properties

Methods

Examples

Example

The following code example demonstrates how to create and use the ContentDispositionHeaderValue class.

using System; using System.Net.Http.Headers; public class Example { public static void Main() { // Create a ContentDispositionHeaderValue for an attachment var header = new ContentDispositionHeaderValue("attachment"); header.FileName = "document.pdf"; header.Size = 102400; // 100 KB Console.WriteLine($"Content-Disposition: {header}"); // Create a ContentDispositionHeaderValue for an inline file var inlineHeader = new ContentDispositionHeaderValue("inline") { FileName = "image.png", Name = "userImage" }; Console.WriteLine($"Content-Disposition: {inlineHeader}"); // Parsing a header string string headerString = "form-data; name=\"file\"; filename=\"report.docx\""; if (ContentDispositionHeaderValue.TryParse(headerString, out var parsedHeader)) { Console.WriteLine("\nParsed Header:"); Console.WriteLine($" Disposition Type: {parsedHeader.DispositionType}"); Console.WriteLine($" Name: {parsedHeader.Name}"); Console.WriteLine($" FileName: {parsedHeader.FileName}"); } } }