LauncherOptions.ContentType | contentType property

Applies to Windows and Windows Phone

Gets or sets the content type that is associated with a URI that represents a file on the network.

Syntax


public string ContentType { get; set; }

Property value

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The content type of the URI.

Remarks

ContentType may only be specified when launching a URI using Launcher.LaunchUriAsync(Uri, LauncherOptions).

The ContentType property allows your app to specify a URI along with a content type. You can use this to associate a URI pointing to a resource on the network with a file type, instead of a URI scheme name. Windows will attempt to use the file type computed from the content type to select the app to launch. The default file handler is then passed the URI instead of a file path. So for example if you have an http:// URI pointing to a .docx file, clicking on it would normally open the browser and begin a file download. By using the ContentType property you can skip the intermediate step and have the default file handler launch immediately. The file handler can then directly access the file on the network using the path embedded in the URI.

If the handler is unable to work directly on the URI, a copy of the file will be downloaded on their behalf.

Because ContentType allows you to directly launch a file handler the same security checks that apply to file launching apply to URI launches with this option specified. See How to launch the default app for a file (C#/VB/C++) and How to launch the default app for a file (JavaScript) for more details on those security checks.

Note  This functionality only works if the default file handler supports being passed a URI to a file on the network. The default file handler must also be able to authenticate with the file’s server. Because of these limitations you should only use the ContentType property if you have thoroughly tested the end to end scenario between your app and the app’s that you expect to handle the files being launched

Examples

Call the Launcher.LaunchUriAsync(Uri, LauncherOptions) method with ContentType set to the content type associated with the URI being launched.


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


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.System
Windows::System [C++]

Metadata

Windows.winmd

See also

Samples
Association launching sample
Tasks
How to launch the default app for a file (JavaScript)
How to launch the default app for a file (C#/VB/C++)
How to launch the default app for a URI (JavaScript)
How to launch the default app for a URI (C#/VB/C++)
Guidelines
Guidelines and checklist for file types and URIs
Reference
LauncherOptions
Launcher.LaunchFileAsync(IStorageFile, LauncherOptions)
Launcher.LaunchUriAsync(Uri, LauncherOptions)

 

 

Show:
© 2014 Microsoft