HttpContentHeaderCollection.ContentDisposition プロパティ

定義

HTTP コンテンツの HTTP Content-Disposition ヘッダーの値を表す HttpContentDispositionHeaderValue オブジェクトを取得または設定します。

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());
}

適用対象

こちらもご覧ください