我正在开发一个Win8(WinRT,C#,XAML)客户端应用程序(CSOM),需要从/向SharePoint 2013下载/上载文件.
如何进行下载/上传?
目前我有代码Documents
在运行时在目录中创建一个文件夹:
using (var context = new Microsoft.SharePoint.Client.ClientContext(sharePointSite))
{
context.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(user, password);
Web web = context.Web;
Microsoft.SharePoint.Client.List docs = web.Lists.GetByTitle(<upper level folder>);
docs.EnableFolderCreation = true;
docs.RootFolder.Folders.Add(folderName);
context.ExecuteQuery();
return true;
}
Run Code Online (Sandbox Code Playgroud)
我在使用此代码创建的文件夹中创建子文件夹时遇到了麻烦.因此,如果我想创建一个名为Feb
under Documents
this 的文件夹就可以了.但是,如果我想创建一个Week 2
在新文件夹下调用的文件夹Feb
.它不会那样做.我收到此错误:
{"List 'Feb' does not exist at site with URL 'https://my.sharepoint.com/sites/labels'."}
我意识到问题可能是docs.RootFolder.Folders.Add(folderName);
因为它Feb
不是根文件夹,当它查找它时会抛出异常.
所以我希望有人可以帮我解决一些代码,将子文件夹添加到已创建的文件夹中.我使用Visual Stuidos 2010并且无法升级到2012,否则我会.我有Microsoft.Sharepoint.Client
可以在VS 2010中引用的2013 dll.
如果您正在使用SharePoint中的客户端对象模型,并且访问尚未初始化或已由其检索的属性
Context.Load(property);
Context.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
你得到一个例子:
Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException
要么
该集合尚未初始化.它没有被请求或者请求没有被执行.
例外.
如果已经初始化/检索这些属性,是否有任何正确的方法可以检查它们?没有Try/Catch方法.我不喜欢那个人.
我想在抛出异常之前检查并处理它.
我已经查过了
方法,但他们没有帮助.IsPropertyAvaiable
仅检查标量属性,并且不会给出结果,例如Web.Lists
,虽然未初始化IsObjectPropertyInstantiated
,Web.Lists
但返回true Web.Lists
.
文件夹工作:
我现在知道如何设置库中文件夹的权限:
public void ChangeItemPermissions()
{
_SharePoint.ClientContext _ClientContext = new _SharePoint.ClientContext("https://sharepoint.oshirowanen.com/sites/oshirodev/");
_ClientContext.Credentials = new NetworkCredential("user", "pass", "oshirowanen.com");
_SharePoint.Principal user = _ClientContext.Web.EnsureUser(@"oshirowanen\tom");
var _List = _ClientContext.Web.Lists.GetByTitle("Library1");
var _Item = _List.LoadItemByUrl("/sites/oshirodev/Library1/Folder1");
var roleDefinition = _ClientContext.Site.RootWeb.RoleDefinitions.GetByType(_SharePoint.RoleType.Reader);
var roleBindings = new _SharePoint.RoleDefinitionBindingCollection(_ClientContext) { roleDefinition };
_Item.BreakRoleInheritance(false,true);
_Item.RoleAssignments.Add(user, roleBindings);
_ClientContext.ExecuteQuery();
}
Run Code Online (Sandbox Code Playgroud)
文件尝试:
我已经尝试将文件名添加到此行:
var _Item = _List.LoadItemByUrl("/sites/oshirodev/Library1/Folder1/File1.docx");
注意(/File1.docx)添加到上面一行的末尾.
收到错误:
但这只是一个错误:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=ItemPermissions
StackTrace:
at ItemPermissions.Form1.ChangeItemPermissions() in c:\Users\Oshirowanen\Documents\Visual Studio 2013\Projects\ItemPermissions\ItemPermissions\Form1.cs:line 46 …
Run Code Online (Sandbox Code Playgroud) 我有指向sharepoint 2013 Office 365的Web服务.我使用客户端对象模型.我正在尝试更新存储4个附件的xml文件.当我在xml文件中有大量二进制数据时执行此操作时,出现以下错误:
信息
请求消息太大了.服务器不允许大于2097152字节的消息.
我意识到我可能不得不分离xml文件中的附件,但目前我的infopath表单将它们存储在那里.有没有办法可以增加请求长度或者可以节省大量的东西.我真的只是修改一个节点,除非我更新xml,否则它将无法工作.谢谢 .代码如下.
我的代码:
ListItem docReq = GetDocRequestLight(docRequestID, businessID);
string fPath = (string)docReq["FileRef"];
using (FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, fPath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fInfo.Stream);
XmlNamespaceManager xmlNameSpaceMgr = new XmlNamespaceManager(xmlDoc.NameTable);
xmlNameSpaceMgr.AddNamespace("my", DocReqXmlNameSpace);
// Get Parent Node
XmlNode node = xmlDoc.SelectSingleNode(GetXPathFromItemKey(velmaKey), xmlNameSpaceMgr);
DateTime outDate;
bool outBool;
if (DateTime.TryParse(newValue, out outDate))
node.InnerText = outDate.ToString("yyyy-MM-dd");
if (Boolean.TryParse(newValue, out outBool))
node.InnerText = newValue;
// Update Statuses
XmlNode statusIDNode = xmlDoc.SelectSingleNode(DocReqStatusIDFieldXPath, xmlNameSpaceMgr);
statusIDNode.InnerText = updatedStatus.ID.ToString();
XmlNode statusNode = xmlDoc.SelectSingleNode(DocReqStatusFieldXPath, …
Run Code Online (Sandbox Code Playgroud) 我还没有找到一个如何获取当前用户然后检查它是否属于特定sharepoint组的具体示例,因为我还没找到任何我无法提供的代码,
赞赏正确的方向.
我们使用Sharepoint 2013 REST API从Sharepoint获取所有新闻项.我们制作了一个自定义的ContentType"Newsitem",其中包含一些属性,包括发布图像字段.
var contentTypeId = "0x01100018B03AC7E8312648AEA00851DEDBCAF802";
var standardUri = "https://examplesite.com/blog/_api/lists/getbytitle('Messages')/items?$top=7&$filter=startswith(ContentTypeId,'" + contentTypeId + "')";
var selectiveUri = "https://examplesite.com/blog/_api/lists/getbytitle('Messages')/items?$top=7&$filter=startswith(ContentTypeId,'" + contentTypeId + "')&$Select=Title,Teaser,Body,ShowAt,TeaserImg";
Run Code Online (Sandbox Code Playgroud)
使用standardUri进行我的REST调用,我检索所有属性但没有TeaserImg.明确选择TeaserImg会使呼叫失败.
为什么我找不到TeaserImg,这不是可能的Sharepoint 2013 REST Api,我应该使用CSOM吗?
我正在尝试使用客户端对象模型(CSOM)从SharePoint中提取所有项目信息.以下是我获取项目信息的方式:
projectContext.Load(projectContext.Projects,
c =>
c.Where(p => p.Id == new Guid(id))
.IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description));
projectContext.Load(projectContext.LookupTables, c => c.Include(f => f.Id, f => f.Entries));
projectContext.Load(projectContext.Web.SiteUsers);
projectContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
但是,我还需要从这些项目中检索FieldValues属性,我无法弄清楚如何将它包含在同一个查询中.我从上面的代码中检索项目后,发现如何在项目级别上执行此操作,如下所示:
var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);
projectContext.ExecuteQuery();
var fieldValues = pubProject.FieldValues;
Run Code Online (Sandbox Code Playgroud)
现在pubProject将包含FieldValues信息,但是对所有项目使用该方法变得太慢(调用SharePoint需要1到4秒),因为我需要为每个项目提出额外请求,CSOM的最佳实践是尽量少打电话.
如果我在include
字段中包含FieldValues ,如下所示:
projectContext.Load(projectContext.Projects,
c =>
c.Where(p => p.Id == new Guid(id))
.IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
f => f.StartDate, …
Run Code Online (Sandbox Code Playgroud) 我使用CSOM在C#中编码,我的应用程序将模板asp.net页面上传到"/ Pages /"库,我需要它在文件上传之前检查该位置是否存在同名的文件(然后可能它可以返回一个bool值).
我确实快速浏览了一下,但我发现的大多数解决方案都提到了使用Javascript,或者应用于本地部署.
如果有人能指出我正确的方向,我会很感激.
我们已将一个AD组添加到SharePoint用户组.现在,当我们使用用户登录时,我们要检查已登录AD用户的权限.