Share via


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:
 property IMap<Platform::String ^, RandomAccessStreamReference ^> ^ ResourceMap { IMap<Platform::String ^, RandomAccessStreamReference ^> ^ get(); };
IMap<winrt::hstring, RandomAccessStreamReference const&> ResourceMap();
public IDictionary<string,RandomAccessStreamReference> ResourceMap { get; }
var iMap = dataPackage.resourceMap;
Public ReadOnly Property ResourceMap As IDictionary(Of String, RandomAccessStreamReference)

Property Value

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

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.

Applies to