共用方式為


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

適用於

另請參閱