每个'listItem'都包含项目,如何获取它们?我试了一会然后才失败,
帮忙,谢谢
camlQuery来自网上的一些测试和示例,没有帮助(有很多变化)
ClientContext clientContext = new ClientContext("http://xxx.xxx.com");
List list = clientContext.Web.Lists.GetById(new Guid("{F91A0F26-2826-4B3B-AF30-ED7DE4494C7B}"));
clientContext.Load(list);
clientContext.ExecuteQuery();
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<queryOptions><QueryOptions><ViewAttributes Scope='RecursiveAll'/><Folder></Folder></QueryOptions></queryOptions>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (ListItem listItem in listItems)
{
each lisItem has children/items , how to get them?!
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从文档库中的文件夹中的子文件夹下载txt文件.
我正在使用camlQuery来实现这一目标.不幸的是,我没有得到txt文件的内容.它有0个字节.
public void SaveFolderFiles(string fileName, string libraryName, ClientOM.ClientContext clientContext)
{
ClientOM.List sharedDocumentsList = clientContext.Web.Lists.GetByTitle(libraryName);
ClientOM.CamlQuery camlQuery = new ClientOM.CamlQuery();
camlQuery.FolderServerRelativeUrl = "/Site/Folder/Folder2010/";
camlQuery.ViewXml =
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='FileLeafRef'/>
<Value Type='Text'>" + fileName + @"</Value>
</Eq>
</Where>
<RowLimit>1</RowLimit>
</Query>
</View>";
ClientOM.ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery);
clientContext.Load(sharedDocumentsList);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
if (listItems.Count == 1)
{
ClientOM.ListItem item = listItems[0];
Console.WriteLine("FileLeafRef: {0}", item["FileLeafRef"]);
Console.WriteLine("FileDirRef: {0}", item["FileDirRef"]);
Console.WriteLine("FileRef: {0}", item["FileRef"]);
Console.WriteLine("File Type: {0}", item["File_x0020_Type"]);
ClientOM.FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext, (string)item["FileRef"]);
using (MemoryStream memoryStream = …
Run Code Online (Sandbox Code Playgroud) 我试图使用sharepoint客户端对象模型查看我的站点中的所有列表,以下是我的代码
using (ClientOM.ClientContext ctx =
new ClientOM.ClientContext(UrlTextBox.Text))
{
//Get the site
ClientOM.Web site = ctx.Web;
ctx.Load(site);
//Get Lists
ctx.Load(site.Lists);
//Query
ctx.ExecuteQuery();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出以下错误" 远程服务器返回错误:(500)内部服务器错误 "尝试传递凭据,但没有工作,尝试传递DefaultNetworkCredentials.没运气..
请指教.
因为两天解决问题,我疯了.问题是;
我正在制作一个控制台APP,它使用全局管理员帐户(在制作新订阅时指定为管理员)与SharePoint Online交谈.我想要实现的是,我想使用CSOM为Office 365的每个网站集和子网站添加自定义操作.该代码工作正常,但注册时由Office 365预先创建的根网站集(即https://xyz.sharepoint.com)
对于任何用于根网站收集的租户,它会给出以下错误;
{"SchemaVersion":"15.0.0.0","LibraryVersion":"16.0.3912.1201","ErrorInfo":{"ErrorMessage":"访问被拒绝.您无权执行此操作或访问此资源.", "ErrorValue":null,"TraceCorrelationId":"2a47fd9c-c07b-1000-cfb7-cdffbe3ab83a","ErrorCode": - 2147024891,"ErrorTypeName":"System.UnauthorizedAccessException"},"TraceCorrelationId":"2a47fd9c-c07b-1000 -cfb7-cdffbe3ab83a"}
现在用户是全局管理员.我还再次将该用户添加为网站集管理员.
同一段代码可以在其他网站集(搜索网站集,任何新制作的网站集......)上正常工作.
这是一个代码;
using (ClientContext spcollContext = new ClientContext(web.Url))
{
SecureString passWord = new SecureString();
foreach (char c in strAdminPassword.ToCharArray()) passWord.AppendChar(c);
SharePointOnlineCredentials creds = new SharePointOnlineCredentials(strAdminUser, passWord);
spcollContext.Credentials = creds;
Web currentweb = spcollContext.Web;
spcollContext.Load(currentweb);
spcollContext.ExecuteQuery();
// authCookie = creds.GetAuthenticationCookie(new Uri(web.Url));
var existingActions2 = currentweb.UserCustomActions;
spcollContext.Load(existingActions2);
spcollContext.ExecuteQuery();
var actions2 = existingActions2.ToArray();
foreach (var action in actions2)
{
if (action.Description == "CustomScriptCodeForEachsite" &&
action.Location == "ScriptLink")
{
action.DeleteObject(); …
Run Code Online (Sandbox Code Playgroud) sharepoint sharepoint-clientobject office365 csom sharepoint-online
我想使用客户端对象模型(C#)在SharePoint文档库上创建文件夹.下面是执行此操作的代码.
ContentTypeCollection listContentTypes = list.ContentTypes;
clientContext.Load(listContentTypes, types => types.Include
(type => type.Id, type => type.Name,
type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == "Folder"));
clientContext.ExecuteQuery();
ContentType folderContentType = result.FirstOrDefault();
ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
newItemInfo.LeafName = Foldername;
ListItem newListItem = list.AddItem(newItemInfo);
newListItem["ContentTypeId"] = folderContentType.Id.ToString();
newListItem["Title"] = Foldername;
ewListItem.Update();
clientContext.Load(list);
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
现在我在库上创建了数千个文件夹.那么有什么其他方法我可以使用批量操作来做到这一点,所以客户端到服务器的连接只会被调用一次.
问题是创建文件夹需要花费太多时间,因为对于每个文件夹,它都会调用SharePoint对象.
是否可以使用Sharepoint Client ObjectModel更新Created/Modified字段而无需更新版本?
var file = _ClientContext.Web.GetFileByServerRelativeUrl(serverRelativeUrl);
_ClientContext.Load(file);
_ClientContext.ExecuteQuery();
ListItem listItem = file.ListItemAllFields;
listItem["Created"] = info.SourceFile.CreationTime;
listItem["Modified"] = info.SourceFile.LastWriteTime;
MapMembers(listItem, info.MetaData);
listItem.Update();
Run Code Online (Sandbox Code Playgroud)
listItem.SystemUpdate/Update(false)在Client ObjectModel中不可用.
谢谢
我正在尝试使用客户端对象模型(.Net 4.0)在SharePoint 2010客户端应用程序中通过其路径获取Folder对象.
我需要检查库中是否存在'folderPath'变量描述的文件夹,然后获取Folder对象以进行进一步的操作.为了提高性能,我选择使用CAML查询来过滤列表.
我的代码:
IEnumerable<List> library = this.clientContext.LoadQuery(
this.clientContext.Web.Lists.Where(p => p.Title == this.documentLibrary));
this.clientContext.ExecuteQuery();
List libraryList = library.FirstOrDefault();
//code to handle libraryList == null
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
"<View Scope=\"RecursiveAll\">" +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name=\"FSObjType\"/>" +
"<Value Type=\"Integer\">1</Value>" +
"</Eq>" +
"<Eq>" +
"<FieldRef Name=\"FileRef\" />" +
"<Value Type=\"Text\">" + folderPath + "</Value>" +
"</Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
"</View>";
ListItemCollection items = libraryList.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
到目前为止一切正常.但我不知道如何从项目中获取"文件夹"对象.我试着这样做: …
我无法找到名称空间 SPSite
到目前为止我已导入这些:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.SharePoint;
using System.Collections;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
using System.Data.SqlClient;
using SP = Microsoft.SharePoint.Client;
using System.Data;
namespace GrandPermission
{
class Program
{
static void Main(string[] args)
{
SPSite oSPSite = new SPSite("http://spdevserver:1002/");
}
}
}
Run Code Online (Sandbox Code Playgroud)
而且SPSite
还有其下红线.
我创建了一个SP.List项"lst".我也:
lst.ContentTypesEnabled = true;
lst.Update();
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
我搜索了AvailableContentTypes并找到了我要添加到lst的那个.然后我:
SP.ContentTypeCollection lstTypeCollection = lst.ContentTypes;
Run Code Online (Sandbox Code Playgroud)
......现在我被卡住了.
我lstTypeCollection.Add()
想要一个ContentTypeCreationInformation
物体,我在黑暗中徘徊.
你能摆脱光明吗?提前致谢 :-)
我想下载我的sharepoint列表的所有文件.我用这种方法下载文件:
public void DownloadFilesOfSpecialtys( )
{
using (var clientContext = new ClientContext(url))
{
foreach (var item in ids)
{
int listItemId = int.Parse(item.ToString());
statics.files = int.Parse(ids.Count.ToString());
var list = clientContext.Web.Lists.GetByTitle(listtitle);
var listItem = list.GetItemById(listItemId);
clientContext.Load(list);
clientContext.Load(listItem, i => i.File);
clientContext.ExecuteQuery();
var fileRef = listItem.File.ServerRelativeUrl;
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
var fileName = Path.Combine(@path , (string)listItem.File.Name);
using (var fileStream = System.IO.File.Create(fileName))
{
fileInfo.Stream.CopyTo(fileStream);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,子文件夹中的文件没有使用此方法下载.有机会浏览列表中的所有子文件夹并下载所有文件吗?
c# directory sharepoint subdirectory sharepoint-clientobject