LauncherOptions.ContentType Properti

Definisi

Mendapatkan atau mengatur tipe konten yang terkait dengan URI yang mewakili file di jaringan.

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

Nilai Properti

String

Platform::String

winrt::hstring

Jenis konten URI.

Contoh

Panggil metode Launcher.LaunchUriAsync(Uri, LauncherOptions) dengan ContentType yang diatur ke jenis konten yang terkait dengan URI yang diluncurkan.

// 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

Keterangan

ContentType hanya dapat ditentukan saat meluncurkan URI menggunakan Launcher.LaunchUriAsync(Uri, LauncherOptions).

Properti ContentType memungkinkan aplikasi Anda menentukan URI bersama dengan jenis konten. Anda dapat menggunakan ini untuk mengaitkan URI yang menunjuk ke sumber daya di jaringan dengan jenis file, bukan nama skema URI. Windows akan mencoba menggunakan tipe file yang dihitung dari tipe isi untuk memilih aplikasi yang akan diluncurkan. Handler file default kemudian melewati URI alih-alih jalur file. Jadi misalnya jika Anda memiliki URI http:// yang menunjuk ke file .docx, mengkliknya biasanya akan membuka browser dan memulai unduhan file. Dengan menggunakan properti ContentType , Anda dapat melewati langkah perantara dan segera meluncurkan handler file default. Handler file kemudian dapat langsung mengakses file di jaringan menggunakan jalur yang disematkan dalam URI.

Jika handler tidak dapat bekerja langsung pada URI, salinan file akan diunduh atas nama mereka.

Karena ContentType memungkinkan Anda untuk langsung meluncurkan penangan file, pemeriksaan keamanan yang sama yang berlaku untuk peluncuran file berlaku untuk peluncuran URI dengan opsi ini ditentukan. Lihat Meluncurkan aplikasi default untuk file untuk detail selengkapnya tentang pemeriksaan keamanan tersebut.

Catatan

Fungsionalitas ini hanya berfungsi jika penangan file default mendukung diteruskan URI ke file di jaringan. Handler file default juga harus dapat mengautentikasi dengan server file. Karena keterbatasan ini, Anda hanya boleh menggunakan properti ContentType jika Anda telah menguji skenario end to end secara menyeluruh antara aplikasi Anda dan aplikasi yang Anda harapkan untuk menangani file yang diluncurkan

Penting

Properti ini hanya diimplementasikan pada perangkat Desktop.

Berlaku untuk

Lihat juga