LauncherOptions.ContentType プロパティ

定義

ネットワーク上のファイルを表す URI に関連付けられているコンテンツ タイプを取得または設定します。

public:
 property Platform::String ^ ContentType { Platform::String ^ get(); void set(Platform::String ^ value); };
winrt::hstring ContentType();

void ContentType(winrt::hstring value);
public string ContentType { get; set; }
var string = launcherOptions.contentType;
launcherOptions.contentType = string;
Public Property ContentType As String

プロパティ値

String

Platform::String

winrt::hstring

URI のコンテンツ タイプ。

起動中の URI に関連付けられたコンテンツ タイプに ContentType が設定されている Launcher.LaunchUriAsync(Uri, LauncherOptions) メソッドを呼び出します。

// The URI to launch
string uriToLaunch = @"http://www.contoso.com/SomeFile.docx";
var uri = new Uri(uriToLaunch);

async void DefaultLaunch()
{
   // Set the URI's content type
   var options = new Windows.System.LauncherOptions();
   options.ContentType = "application/vnd.ms-word.document.12";

   // Launch the URI with the content type
   var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);

   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
// The URI to launch.
Windows::Foundation::Uri m_uri{ L"http://www.contoso.com/SomeFile.docx" };

Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Set the URI's content type.
    Windows::System::LauncherOptions launcherOptions;
    launcherOptions.ContentType(L"application/vnd.ms-word.document.12");

    // Launch the URI.
    if (co_await Windows::System::Launcher::LaunchUriAsync(m_uri, launcherOptions))
    {
        // URI launched.
    }
    else
    {
        // URI launch failed.
    }
}
// The URI to launch.
auto uri = ref new Windows::Foundation::Uri("http://www.contoso.com/SomeFile.docx");

void MainPage::DefaultLaunch()
{
   // Set the URI's content type
   auto launchOptions = ref new Windows::System::LauncherOptions();
   launchOptions->ContentType = "application/vnd.ms-word.document.12";

   // Launch the URI with the content type
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri, launchOptions));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}
' The URI to launch
Dim uri As New Uri("http://www.contoso.com/SomeFile.docx")

async Sub DefaultLaunch()

   ' Set the URI's content type
   Dim options = Windows.System.LauncherOptions()
   options.ContentType = "application/vnd.ms-word.document.12"

   ' Launch the URI with the content type
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri, options)

   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If

End Sub

注釈

ContentType は、 Launcher.LaunchUriAsync(Uri, LauncherOptions) を使用して URI を起動する場合にのみ指定できます。

ContentType プロパティを使用すると、アプリでコンテンツ タイプと共に URI を指定できます。 これを使用すると、ネットワーク上のリソースを指す URI を URI スキーム名ではなくファイルの種類に関連付けることができます。 Windows は、コンテンツ タイプから計算されたファイルの種類を使用して、起動するアプリを選択しようとします。 既定のファイル ハンドラーには、ファイル パスではなく URI が渡されます。 たとえば、.docx ファイルを指す http:// URI がある場合は、通常、それをクリックするとブラウザーが開き、ファイルのダウンロードが開始されます。 ContentType プロパティを使用すると、中間ステップをスキップして、既定のファイル ハンドラーをすぐに起動できます。 その後、ファイル ハンドラーは、URI に埋め込まれたパスを使用して、ネットワーク上のファイルに直接アクセスできます。

ハンドラーが URI で直接動作できない場合は、ファイルのコピーが代わりにダウンロードされます。

ContentType を使用すると、ファイル ハンドラーを直接起動できるため、ファイルの起動に適用されるのと同じセキュリティ チェックが、このオプションを指定した URI 起動に適用されます。 これらのセキュリティ チェックの詳細については、「 ファイルの既定のアプリを起動 する」を参照してください。

注意

この機能は、既定のファイル ハンドラーで URI がネットワーク上のファイルに渡されることをサポートしている場合にのみ機能します。 既定のファイル ハンドラーは、ファイルのサーバーで認証できる必要もあります。 これらの制限のため、 ContentType プロパティは、アプリと起動中のファイルを処理する予定のアプリの間でエンド ツー エンドのシナリオを十分にテストした場合にのみ使用する必要があります

重要

このプロパティは、デスクトップ デバイスでのみ実装されます。

適用対象

こちらもご覧ください