SharePoint 2010 - 客户端对象模型 - 向 ListItem 添加附件 [英] SharePoint 2010 - Client Object Model - Add attachment to ListItem

查看:32
本文介绍了SharePoint 2010 - 客户端对象模型 - 向 ListItem 添加附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SharePoint 列表,我将使用客户端对象模型向其中添加新的 ListItem.添加 ListItems 不是问题,而且效果很好.

I have a SharePoint List to which I'm adding new ListItems using the Client Object Model. Adding ListItems is not a problem and works great.

现在我想添加附件.

我以下列方式使用 SaveBinaryDirect:

I'm using the SaveBinaryDirect in the following manner:

File.SaveBinaryDirect(clientCtx, url.AbsolutePath + "/Attachments/31/" + fileName, inputStream, true);

只要我尝试将附件添加到的项目已经有一个通过 SharePoint 网站添加的附件并且不使用客户端对象模型,它就可以正常工作.

It works without any problem as long as the item that I'm trying to add the attachment to, already has an attachment that was added through the SharePoint site and not using the Client Object Model.

当我尝试向还没有任何附件的项目添加附件时,我收到以下错误(这两种情况都会发生,但不是同一个文件 - 但是这两条消息始终显示):

When I try to add an attachment to a item that doesnt have any attachments yet, I get the following errors (both happen but not with the same files - but those two messages appear consistently):

The remote server returned an error: (409) Conflict

The remote server returned an error: (404) Not Found

我想我可能需要先为此项目创建附件文件夹.当我尝试以下代码时:

I figured that maybe I need to create the attachment folder first for this item. When I try the following code:

clientCtx.Load(ticketList.RootFolder.Folders);
clientCtx.ExecuteQuery();
clientCtx.Load(ticketList.RootFolder.Folders[1]);             // 1 -> Attachment folder
clientCtx.Load(ticketList.RootFolder.Folders[1].Folders);
clientCtx.ExecuteQuery();
Folder folder = ticketList.RootFolder.Folders[1].Folders.Add("33");
clientCtx.ExecuteQuery();

我收到一条错误消息:

Cannot create folder "Lists/Ticket System/Attachment/33"

我拥有 SharePoint 网站/列表的完全管理员权限.

I have full administrator rights for the SharePoint site/list.

任何想法我可能做错了什么?

Any ideas what I could be doing wrong?

谢谢,托尔本

推荐答案

我已经和微软讨论过这个问题.看起来远程创建附件的唯一方法是 List.asmx Web 服务.我也尝试创建此子文件夹,但没有成功.

I have discussed this question with Microsoft. Looks like that only one way to create attachments remotely is List.asmx web service. I have tried to create this subfolder also and with no success.

这篇关于SharePoint 2010 - 客户端对象模型 - 向 ListItem 添加附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆