Share via


AtomPubClient.CreateResourceAsync(Uri, String, SyndicationItem) Method

Definition

Creates a new Entry resource in the specified collection. The Uri of the collection in which to create the new resource can be discovered from the ResourceCollection object retrieved from the RetrieveResourceAsync method.

public:
 virtual IAsyncOperationWithProgress<SyndicationItem ^, TransferProgress> ^ CreateResourceAsync(Uri ^ uri, Platform::String ^ description, SyndicationItem ^ item) = CreateResourceAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<SyndicationItem, TransferProgress> CreateResourceAsync(Uri const& uri, winrt::hstring const& description, SyndicationItem const& item);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<SyndicationItem,TransferProgress> CreateResourceAsync(System.Uri uri, string description, SyndicationItem item);
function createResourceAsync(uri, description, item)
Public Function CreateResourceAsync (uri As Uri, description As String, item As SyndicationItem) As IAsyncOperationWithProgress(Of SyndicationItem, TransferProgress)

Parameters

uri
Uri Uri

The Uri of the specified collection in which the new resource should be created.

description
String

Platform::String

winrt::hstring

The description of the new resource that is turned into the Slug: header of the POST request.

item
SyndicationItem

The new resource to be created.

Returns

The object that is used to create the resource asynchronously and to report the progress and completion status of the operation.

Attributes

Examples

The following code demonstrates how to access a service document and retrieve edit URI values. For additional examples of how AtomPub can be used to manage feed content, download the AtomPub sample.

function createResource() {
    try {
        // Refresh client in case server url or credential have changed.
        createClient();

        var title = document.getElementById("titleField").value;
        if (title === "") {
            outputField.innerHTML = "Post title cannot be blank";
            return;
        }

        var serviceUri = new Windows.Foundation.Uri(document.getElementById("serviceAddressField").value.trim() + defaultServiceDocUri);
        outputField.innerHTML = "Fetching service document: " + serviceUri.absoluteUri + "</br>";
        findEditUri(serviceUri).then(function (resourceUri) {
            if (!resourceUri) {
                outputField.innerHTML += "Error: Edit uri not found in service document";
                return null;
            }

            outputField.innerHTML += "Uploading post: " + resourceUri.absoluteUri + "</br>";

            var item = new Windows.Web.Syndication.SyndicationItem();
            item.title = new Windows.Web.Syndication.SyndicationText(title, Windows.Web.Syndication.SyndicationTextType.text);
            var content = document.getElementById("bodyField").value;
            item.content = new Windows.Web.Syndication.SyndicationContent(content, Windows.Web.Syndication.SyndicationTextType.html);

            return client.createResourceAsync(resourceUri, item.title.text, item);
        }).done(function (result) {
            if (result) {
                outputField.innerHTML += "Posted at " + result.itemUri.absoluteUri + "</br>";
                outputField.innerHTML += "Complete</br>";
            }
        }, onError);
    }
    catch (ex) {
        outputField.innerHTML += "Exception:" + ex + "</br>";
    }
}

Note

See RetrieveServiceDocumentAsync for the code behind the findEditUri function called in this example.

Applies to

See also