我有点像SharePoint noobie所以请耐心等待.
我需要能够使用客户端对象模型在我们的自定义列表中创建一个新的列表项.我一直在关注MSDN网站上描述的示例,并且大多数情况下这都有效.
我们有一个包含多个字段的列表,包括UserMulti字段类型.我在向此字段添加用户时遇到问题.到目前为止,我已经尝试了以下内容,但这似乎总是默认为系统帐户而不是字段中指定的用户.
...
listItem["ProjectMembers"] = "1;#domain\\johndoe";
listItem.Update();
_clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
我是否需要先进行某种类型的查找?任何帮助表示赞赏.谢谢.
假设我有2个列表:团队和员工.每个团队都有许多员工:
Teams
ID
Name
Employees
ID
Name
TeamID (foreign key of Teams)
Run Code Online (Sandbox Code Playgroud)
是否可以在SharePoint JSOM中编写查询,以便我可以沿着以下行执行某些操作(在查询执行/加载之后):
var employeesListItems = teamListItem.get_item("Employees")
Run Code Online (Sandbox Code Playgroud)
SharePoint对象模型是否以任何方式支持此功能?
澄清:我的意图是尽可能多地重用ClientObject.我知道我可以查询所有员工和所有团队,为每个团队创建一组自定义对象,然后迭代员工并将他们推送到相关Team对象的"Employees"字段.我想避免这样做.
sharepoint sharepoint-2010 sharepoint-clientobject sharepoint-2013
我有一个自定义列表表单,我们需要在文档库中创建一个文件夹,其文件夹名称等于列表项目标题.然后应该立即在新创建的文件夹中创建3个文件夹.我可以在捕获列表项标题后创建顶级文件夹,但不知道如何在这个新创建的文件夹中创建子文件夹.有什么输入吗?
下面显示的代码,适用于创建顶级文件夹.需要知道,如何添加三个子文件夹.
function retrieveWebSite() {
var clientContext;
var oWebsite;
var oList;
var itemCreateInfo;
clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("Docs");
itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName("Top Folder");
this.oListItem = oList.addItem(itemCreateInfo);
this.oListItem.update();
clientContext.load(this.oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
function successHandler() {
alert('success');
}
function errorHandler() {
alert('fail');
}
}
Run Code Online (Sandbox Code Playgroud)
下面的代码感谢Vadim Gremyachev。我的目标是使用授予用户对某些SharePoint
文件夹的访问权限CSOM
。我试图实现的目标是访问称为的库JZhu
,在JZhu
库内部,我有两个文件夹folder1
和folder2
。我正在尝试向授予Reader
许可folder1
。到目前为止,该代码无法正常工作,因为在第6行出现异常:
字段或属性“ ListItemAllFields”不存在
ClientContext context = new ClientContext("http://myRealUrl");
Principal user = context.Web.EnsureUser(@"myLoginAccout");
var folder = context.Web.GetFolderByServerRelativeUrl("JZhu/folder1");
var roleDefinition = context.Site.RootWeb.RoleDefinitions.GetByType(RoleType.Reader); //get Reader role
var roleBindings = new RoleDefinitionBindingCollection(context) { roleDefinition };
folder.ListItemAllFields.BreakRoleInheritance(true, false); //line 6
folder.ListItemAllFields.RoleAssignments.Add(user, roleBindings);
context.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud) 我尝试使用客户端对象模型创建一个新的列表项.我已经创建了一个asp.net应用程序来完成任务.如果我传递安装在我的计算机中的SharePoint服务器的URL,它就可以工作.但是,如果我提供我的SharePoint在线URL,它将无法正常工作,如下面的代码所示.我得到"远程服务器返回错误:(403)禁止."错误.任何的想法?
ClientContext context = new ClientContext("https://xxx.sharepoint.com/SitePages/");
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = result.City;
newItem["Body"] = result.State;
newItem.Update();
context.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud) c# sharepoint-2010 sharepoint-clientobject sharepoint-online