HttpContentHeaderCollection.ContentDisposition 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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());
}