DataPackage.ResourceMap DataPackage.ResourceMap DataPackage.ResourceMap DataPackage.ResourceMap DataPackage.ResourceMap Property

Definition

Maps a URI to a file. Used to ensure that referenced content (such as an image) in HTML content is added to the DataPackage.

public : IMap<Platform::String, RandomAccessStreamReference> ResourceMap { get; }
IMap<winrt::hstring, RandomAccessStreamReference> ResourceMap();
public IDictionary<string, RandomAccessStreamReference> ResourceMap { get; }
Public ReadOnly Property ResourceMap As IDictionary<string, RandomAccessStreamReference>
var iDictionary = dataPackage.resourceMap;

Property Value

IDictionary<string, RandomAccessStreamReference> IDictionary<string, RandomAccessStreamReference> IDictionary<string, RandomAccessStreamReference>

Specifies a name/value pair that specifies the an HTML path with a corresponding StreamReference object.

Examples

public void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    string htmlExample = "<p>Here is our store logo: <img src='assets/logo.png'>.</p>";
    string fileExample = "assets\\logo.png";
    RandomAccessStreamReference streamRef = null;
    Windows.Storage.StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileExample);
    try
    {
        streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
    }
    catch (Exception ex)
    {
        // TODO: Handle the exception.
    }
    string htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(htmlExample);
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share HTML Example";
    request.Data.Properties.Description = "An example of how to share HTML.";
    request.Data.SetHtmlFormat(htmlFormat);
    request.Data.ResourceMap[fileExample] = streamRef;
}
function shareHtmlHandler(e) {
    var request = e.request;
    var htmlExample = "<p>Here is our store logo: <img src='images/logo.png'>.</p>";
    var localImage = "images\\logo.png";
    request.data.properties.title = "Share Html Example";
    request.data.properties.description = "A demonstration that shows how to share an HTML fragment with a local image.";
    var deferral = e.request.getDeferral();
    Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(localImage).done(function (imageFile) {
        request.data.setHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(htmlExample));
        request.data.resourceMap[localImage] = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
        deferral.complete();
    }, function (err) {
        request.failWithDisplayText(err);
    });
}

Remarks

HTML content often contains references to other files. The most common example is an img tag that refers to a specific file. To ensure that the image is sent with the rest of the HTML content, you need to use ResourceMap, which maps the URI string to the actual data. You can learn more about this in How to share HTML.