Partilhar via


GetResponseText

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Retrieves a specified part of packaged downloaded data.

retval = downloaderObject.GetResponseText(part)

Arguments

part

string

The name of the specific part of the downloaded content package. part is not an optional parameter. You must specify at least an empty string; otherwise, a syntax error will result.

Managed Equivalent

Managed programming does not use Downloader. See WebClient.

Return Value

Type: object

The downloaded data. As in HTML, the return value can be examined and is passed as a string in a packet, but ultimately it is interpreted by the property you set with this value.

Remarks

Silverlight provides the ability to download content as a package, which is a collection of independent files that contain XAML content, media assets, and other application content. When the package is successfully downloaded, you can use methods such as GetResponseText, SetSource, and CreateFromXamlDownloader to selectively retrieve a specific named part of the package.

The part parameter of the GetResponseText method identifies the specific part to retrieve within the downloaded content.

You generally call this method only from the event handler for a DownloaderCompleted event. Outside this context, there is no guarantee that a GetResponseText return value is valid.

When a Downloader object request is completed, the GetResponseText method returns a representation of the downloaded content as a string value. The return value from GetResponseText can represent XAML content, JavaScript content, or a media asset, such as an image.

If you are not requesting parts of a package and the Downloader request returns only a single asset, you typically would get the ResponseText property instead of GetResponseText. Calling GetResponseText with an empty string returns the same value as ResponseText.

NoteNote:

If you are downloading media assets for use by the Source property of Image and MediaElement objects, you should consider using the SetSource (Image) or SetSource (MediaElement) methods instead of setting an object with GetResponseText or ResponseText, and then setting the Source properties. This is a more efficient way to transfer large media assets. Image also has an equivalent SetSource.

Example

The following JavaScript example shows how to use the GetResponseText method to retrieve a specified part from the downloaded content.

function onDownloadCompleted(sender, eventArgs)
{
    // Retrieve the XAML content from the downloaded package file.
    var jacketBrowserXaml = sender.getResponseText("jacketBrowser.xaml");
    // Create the objects from the XAML content.
    var jacketBrowser = plugin.content.createFromXaml(jacketBrowserXaml);

    // Add downloaded XAML content to the root Canvas of the plug-in.
    sender.findName("root").children.insert(0, jacketBrowser);

    // Retrieve a reference to the Image object representing the jacket.
    var jacketImageSlice = sender.findName("jacketSlice");

    // Set the Source property of the Image object to the specific jacket image
    // within the downloaded .zip package file.
    jacketImageSlice.setSource(sender, "rotation01_green.png");
}

Applies To

Downloader