Jaa


DataPackage.SetHtmlFormat(String) Method

Definition

Adds HTML content to the DataPackage.

public:
 virtual void SetHtmlFormat(Platform::String ^ value) = SetHtmlFormat;
void SetHtmlFormat(winrt::hstring const& value);
public void SetHtmlFormat(string value);
function setHtmlFormat(value)
Public Sub SetHtmlFormat (value As String)

Parameters

value
String

Platform::String

winrt::hstring

The HTML content.

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

To ensure that a target app can process the HTML content, use HtmlFormatHelper.CreateHtmlFormat. It adds the required headers and other information the string containing the HTML.

If your app supports selection or copying/pasting of HTML content that contains img elements, be sure that the src attributes specify fully-qualified absolute paths to the images, not relative paths.

Applies to