Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AtomPubClient.CreateResourceAsync | createResourceAsync method

Applies to Windows and Windows Phone

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.

Syntax


atomPubClient.createResourceAsync(uri, description, item).done( /* Your success and error handlers */ );

Parameters

uri

Type: Windows.Foundation.Uri [JavaScript] | System.Uri [.NET] | Windows::Foundation::Uri [C++]

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

description

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

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

item

Type: SyndicationItem

The new resource to be created.

Return value

Type: IAsyncOperationWithProgress<SyndicationItem, TransferProgress>

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

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.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.AtomPub
Windows::Web::AtomPub [C++]

Metadata

Windows.winmd

See also

Quickstart: Managing Feed Entries
AtomPub sample
AtomPubClient

 

 

Show:
© 2014 Microsoft