ContentDispositionHeaderValue Class
Represents a Content-Disposition header value.
Constructors
-
ContentDispositionHeaderValue(String) (String dispositionType)
Initializes a new instance of the ContentDispositionHeaderValue class.
Parameters
- dispositionType: The disposition type.
Properties
-
DispositionType : String { get; set; }
Gets or sets the disposition type for the Content-Disposition header.
-
FileName : String? { get; set; }
Gets or sets the filename associated with the Content-Disposition header.
-
FileNameStar : String? { get; set; }
Gets or sets the filename* associated with the Content-Disposition header.
-
Name : String? { get; set; }
Gets or sets the name associated with the Content-Disposition header.
-
Parameters : IList<NameValueHeaderValue> { get; }
Gets a collection of parameters associated with the Content-Disposition header.
-
ReadBufferSize : Int64? { get; set; }
Gets or sets the suggested buffer size for reading the content.
Methods
-
Equals(Object?) (Object? obj)
Determines whether the specified object is equal to the current object.
-
GetHashCode() ()
Serves as the default hash function.
-
GetType() ()
Gets the Type of the current instance.
-
Parse(String) (String input)
Parses a Content-Disposition header value.
Parameters
- input: The string to parse.
Returns
The parsed ContentDispositionHeaderValue.
-
ToString() ()
Converts the ContentDispositionHeaderValue to its string representation.
-
TryParse(String, out ContentDispositionHeaderValue?) (String input, out ContentDispositionHeaderValue? result)
Tries to parse a Content-Disposition header value.
Parameters
- input: The string to parse.
- result: When this method returns, contains the parsed ContentDispositionHeaderValue, if the parsing succeeded, or null otherwise.
Returns
true if the string was parsed successfully; otherwise, false.
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}");
}
}
}