HttpContentHeaderCollection.ContentDisposition 属性

定义

获取或设置 HttpContentDispositionHeaderValue 对象,该对象代表 HTTP 内容上的 HTTP Content-Disposition 标头的值。

public:
 property HttpContentDispositionHeaderValue ^ ContentDisposition { HttpContentDispositionHeaderValue ^ get(); void set(HttpContentDispositionHeaderValue ^ value); };
HttpContentDispositionHeaderValue ContentDisposition();

void ContentDisposition(HttpContentDispositionHeaderValue value);
public HttpContentDispositionHeaderValue ContentDisposition { get; set; }
var httpContentDispositionHeaderValue = httpContentHeaderCollection.contentDisposition;
httpContentHeaderCollection.contentDisposition = httpContentDispositionHeaderValue;
Public Property ContentDisposition As HttpContentDispositionHeaderValue

属性值

表示 HTTP 内容上的 HTTP Content-Disposition 标头值的对象。 null 值表示标头不存在。

注解

下面的示例代码演示了使用 HttpContentHeaderCollection 对象上的 ContentDisposition 属性获取或设置 HTTP 内容的 Content-Disposition 标头值的方法。

// Content-Disposition header
// HttpContentDispositionHeaderValue
void DemoContentDisposition(IHttpContent content) {
    var h = content.Headers;

    HttpContentDispositionHeaderValue value;
    bool ok = HttpContentDispositionHeaderValue.TryParse("attachment; filename=\"myfile.txt\"; myparam=myvalue", out value);
    h.ContentDisposition = value;

    h.ContentDisposition = HttpContentDispositionHeaderValue.Parse("attachment; filename=\"myfile.txt\"; myparam=myvalue");
    var header = h.ContentDisposition;

    uiLog.Text += "\nCONTENT DISPOSITION HEADER\n";
    // Content-Disposition: attachment; filename="fname.ext"

    // ContentDisposition is a HttpContentDispositionHeaderValue and contains:
    // DispositionType, FileName, FileNameStar, Name: all strings
    // Size: nullable long
    // Parameters: IList<HttpNameValueHeaderValue> 
    var parameterString = "";
    foreach (var parameter in header.Parameters) {
        parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
    }
    if (parameterString == "") {
        parameterString = "(no parameters)";
    }

    uiLog.Text += string.Format("ContentDisposition: DispositionType: {0} FileName: {1} FileNameStar: {2} Name: {3} Parameters: {4} Size: {5} ToString: {6}\n\n", 
    header.DispositionType, header.FileName, header.FileNameStar, header.Name, parameterString, header.Size, header.ToString());
}

适用于

另请参阅