AtomPubClient.CreateResourceAsync(Uri, String, SyndicationItem) 方法

定义

在指定的集合中创建新的 Entry 资源。 可以从从 RetrieveResourceAsync 方法检索到的 ResourceCollection 对象中发现要在其中创建新资源的集合的 URI。

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)

参数

uri
Uri Uri

应在其中创建新资源的指定集合的 URI。

description
String

Platform::String

winrt::hstring

转换为 POST 请求的 Slug: 标头的新资源的说明。

item
SyndicationItem

要创建的新资源。

返回

用于异步创建资源并报告操作进度和完成状态的 对象。

属性

示例

以下代码演示如何访问服务文档和检索编辑 URI 值。 有关如何使用 AtomPub 管理源内容的其他示例,请下载 AtomPub 示例

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

注意

有关此示例中调用的 findEditUri 函数背后的代码,请参阅 RetrieveServiceDocumentAsync

适用于

另请参阅