3

専門家に聞いてみたい。

SharePoint 2013 で REST API を使用して添付ファイルをリスト アイテムに添付する方法を知っている人はいますか? 以下の文書を検索しました。しかし、リスト アイテムの添付ファイルとしてファイルをアップロードすることに関する情報はありません。

http://msdn.microsoft.com/en-us/library/fp142386.aspx

追加情報:

以下の記事を見つけました。

http://chuvash.eu/2013/02/20/rest-api-add-a-plain-text-file-as-an-attachment-to-a-list-item/

記事によると、以下のJavascriptコードを使用してリストアイテムに添付ファイルをアップロードすることが可能です。C#を使いたいです。私は今試していますが、まだ成功していません。

var content = "Hello, this text is inside the file created with REST API";
var digest = $("#__REQUESTDIGEST").val();
var composedUrl = "/_api/web/lists/GetByTitle('List1')/items(1)/AttachmentFiles/add(FileName='readme.txt')";
$.ajax({
    url: composedUrl,
    type: "POST",
    data: content,
    headers: {        
        "X-RequestDigest": digest
    }
})
4

2 に答える 2

0

これを使用してみてください:

var executor = new SP.RequestExecutor(appweburl);
var digest = $("#__REQUESTDIGEST").val();
var content = "Hello, this text is inside the file created with REST API";

executor.executeAsync(
{
url: appweburl +           "/_api/web/lists/getbytitle('List1')/items(1)/AttachmentFiles/add(FileName='readme.txt)",
method: "POST",
body: content,
headers: {
          "X-RequestDigest": digest
         },
success: function(data) {
         toastr.success('Document attached successfully.');
         },
error: function(err) {
         toastr.error('Oops! Document attached created fail.');
         }
}
);
于 2014-07-02T02:38:17.107 に答える