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

查看:214
本文介绍了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.

现在,我要添加附件.

Now I want to add attachments.

我以以下方式使用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();

我收到一条错误消息,内容为:

I receive an error message saying:

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?

谢谢,索本

推荐答案

我已经与Microsoft讨论了这个问题.看起来,只有一种远程创建附件的方法是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天全站免登陆