Share​Operation Share​Operation Share​Operation Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

Prerelease. Handles the bulk of the work during a share operation. This includes the data that the user wants to share, setting or removing QuickLinks, and informing the system about the status of the operation.

public : sealed class ShareOperation : IShareOperation, IShareOperation2, IShareOperation3public sealed class ShareOperation : IShareOperation, IShareOperation2, IShareOperation3Public NotInheritable Class ShareOperation Implements IShareOperation, IShareOperation2, IShareOperation3
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following example shows how to work with the ShareOperation object.

var shareOperation = eventObject.detail.shareOperation;
if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
    shareOperation.data.getTextAsync().done(function (text) {
            // To output the text using this example, 
            // you need a div tag with an id of "output" in your HTML file.
            document.getElementById("output").innerText = text;
        }, function (e) {
            displayError("Error retrieving Text format: " + e);
        }
    });
}

Remarks

When a user selects your app as the target of a share action, an activated event fires. The object that this event sends to your app contains the instance of the ShareOperation class.

An app currently open as a Share target cannot initiate an additional ShareOperation, or launch a FileOpenPicker or FileSavePicker.

All ShareOperation APIs should only be called after the CoreWindow for the Share target has been activated. The Share platform creates an entry for share operation only after the window has been activated.

Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Properties

Contacts Contacts Contacts

Prerelease.

public : IVectorView<Contact> Contacts { get; }public IReadOnlyList<Contact> Contacts { get; }Public ReadOnly Property Contacts As IReadOnlyList<Contact>
Value
IVectorView<Contact> IReadOnlyList<Contact> IReadOnlyList<Contact>
Attributes
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16190.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Data Data Data

Contains a DataPackage object with the data that the user wants to share.

public : DataPackageView Data { get; }public DataPackageView Data { get; }Public ReadOnly Property Data As DataPackageView
Value
DataPackageView DataPackageView DataPackageView

Contains the data that the user wants to share.

Attributes

Examples

The following example shows how to get the DataPackageView object from the data property. To use the code in this example, add event listener to your app to handle the activated event. Then put this code in the function that this event listener calls.

if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.shareTarget) {
    shareOperation = eventArgs.shareOperation;
    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
        var output = document.createElement("div");
        var shareData = shareOperation.data.getText();
        output.innerText = shareData;
        document.body.appendChild(output);
        shareOperation.reportCompleted();
    }
}

QuickLinkId QuickLinkId QuickLinkId

A string that contains the ID of a QuickLink.

public : PlatForm::String QuickLinkId { get; }public string QuickLinkId { get; }Public ReadOnly Property QuickLinkId As string
Value
PlatForm::String string string

The ID of the QuickLink.

Attributes

Methods

DismissUI() DismissUI() DismissUI()

Closes the share pane.

public : void DismissUI()public void DismissUI()Public Function DismissUI() As void
Attributes

Remarks

Call the DismissUI method to dismiss the share pane programmatically. Calling DismissUI is similar to the user dismissing the share pane by tapping away from it. If the share operation takes a long time, the app continues to run in the background. If the operation isn't long-running, it has 10 seconds to run before being terminated.

RemoveThisQuickLink() RemoveThisQuickLink() RemoveThisQuickLink()

Removes the QuickLink from the list of QuickLinks that are available to the user.

public : void RemoveThisQuickLink()public void RemoveThisQuickLink()Public Function RemoveThisQuickLink() As void
Attributes

ReportCompleted() ReportCompleted() ReportCompleted()

Specifies that the sharing operation is complete.

public : void ReportCompleted()public void ReportCompleted()Public Function ReportCompleted() As void
Attributes

Examples

The following example shows how a target app might respond to a share operation. Notice the use of reportComplete when the target app has finished processing the data.

if (eventArgs.kind === Windows.ApplicationModel.Activation.ActivationKind.shareTarget) {
    shareOperation = eventArgs.shareOperation;
    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
        var output = document.createElement("div");
        var shareData = shareOperation.data.getText();
        output.innerText = shareData;
        document.body.appendChild(output);
        shareOperation.reportCompleted();
    }
}

Remarks

When your app acts as a target for a share operation, it should call reportComplete after it has processed the data being shared. This method closes the app window and returns the user to the source app.

See Also

ReportCompleted(QuickLink) ReportCompleted(QuickLink) ReportCompleted(QuickLink)

Specifies that the sharing operation is complete. A QuickLink that the system can save as a shortcut for future sharing operations is included.

public : void ReportCompleted(QuickLink quicklink)public void ReportCompleted(QuickLink quicklink)Public Function ReportCompleted(quicklink As QuickLink) As void
Parameters
quicklink
QuickLink QuickLink QuickLink

A QuickLink object that the system saves as a shortcut for future sharing operations.

Attributes
See Also

ReportDataRetrieved() ReportDataRetrieved() ReportDataRetrieved()

Specifies that the app has acquired the content that the user wants to share.

public : void ReportDataRetrieved()public void ReportDataRetrieved()Public Function ReportDataRetrieved() As void
Attributes

Remarks

This method does nothing when called on Windows Phone 8.1.

ReportError(String) ReportError(String) ReportError(String)

Specifies that an error occurred during the sharing operation.

public : void ReportError(PlatForm::String value)public void ReportError(String value)Public Function ReportError(value As String) As void
Parameters
value
PlatForm::String String String

Specifies the error message. The system displays this message to the user.

Attributes

ReportStarted() ReportStarted() ReportStarted()

Specifies that the app has started to acquire the content that the user wants to share.

public : void ReportStarted()public void ReportStarted()Public Function ReportStarted() As void
Attributes

Remarks

Note

This method does nothing when called on Windows Phone 8.1.

ReportSubmittedBackgroundTask() ReportSubmittedBackgroundTask() ReportSubmittedBackgroundTask()

Specifies that the app has requested that the system allow the sharing operation to run as a background task.

public : void ReportSubmittedBackgroundTask()public void ReportSubmittedBackgroundTask()Public Function ReportSubmittedBackgroundTask() As void
Attributes

Remarks

Note

This method does nothing when called on Windows Phone 8.1.

See Also