ShareOperation ShareOperation ShareOperation ShareOperation Class

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.

Syntax

Declaration

public sealed class ShareOperationpublic sealed class ShareOperationPublic NotInheritable Class ShareOperation

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).

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

Properties summary

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

A string that contains the ID of a QuickLink.

Methods summary

Closes the share pane.

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

Specifies that the sharing operation is complete.

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

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

Specifies that an error occurred during the sharing operation.

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

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

Properties

  • Data
    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

    Property Value

    Remarks

    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
    QuickLinkId

    A string that contains the ID of a QuickLink.

    public string QuickLinkId { get; }public string QuickLinkId { get; }Public ReadOnly Property QuickLinkId As string

    Property Value

    • string
      string
      string
      string

      The ID of the QuickLink.

Methods

  • DismissUI()
    DismissUI()
    DismissUI()
    DismissUI()

    Closes the share pane.

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

    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.

  • ReportCompleted()
    ReportCompleted()
    ReportCompleted()
    ReportCompleted()

    Specifies that the sharing operation is complete.

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

    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.

    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();
        }
    }
    
  • ReportDataRetrieved()
    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

    Remarks

    This method does nothing when called on Windows Phone 8.1.

  • ReportError(System.String)
    ReportError(System.String)
    ReportError(System.String)
    ReportError(System.String)

    Specifies that an error occurred during the sharing operation.

    public void ReportError(System.String value)public void ReportError(System.String value)Public Function ReportError(value As System.String) As void

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

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

  • ReportStarted()
    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

    Remarks

    Note

    This method does nothing when called on Windows Phone 8.1.

  • ReportSubmittedBackgroundTask()
    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

    Remarks

    Note

    This method does nothing when called on Windows Phone 8.1.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.ApplicationModel.DataTransfer.ShareTarget.dll