我正在开发一个从sharepoint检索文件的界面。我有以下方法上传文件:
public bool UploadDocument(string document)
{
if (String.IsNullOrEmpty(Path.GetFullPath(document)))
{
return false;
}
var site = GetNewDataContext(SiteUrl);
try
{
using (var clientContext = GetNewContext())
{
var uploadLocation = string.Format("{0}{1}/{2}", SiteUrl, Helpers.ListNames.RequestedDocuments, Path.GetFileName(document));
//Get Document List
var documentslist = clientContext.Web.Lists.GetByTitle(Helpers.ListNames.RequestedDocuments);
var fileCreationInformation = new FileCreationInformation
{
Content = System.IO.File.ReadAllBytes(document), //Assign to content byte[] i.e. documentStream
Overwrite = true, //Allow owerwrite of document
Url = uploadLocation //Upload URL
};
var uploadFile = documentslist.RootFolder.Files.Add(fileCreationInformation);
uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();
}
site.SubmitChanges(ConflictMode.FailOnFirstConflict, true);
}
catch (Exception exception)
{
throw new ApplicationException(exception.Message);
}
return true;
}
但是,我的下一步是应用自定义权限..我在网上发现了一些博客,演示了如何执行此操作: http://howtosharepoint.blogspot.com/2010/10/programmatically-add-delete-modify-item.html
我的下载方法返回一个ListItem ..我怎么能这样做一个SPListItem
private static ListItemCollection GetListItemCollectionFromSp(string documentListName, string name, string value, string type, int rowLimit)
{
ListItemCollection listItems = null;
using (var ctx = GetNewContext())
{
var documentsList = ctx.Web.Lists.GetByTitle(documentListName);
var camlQuery = new CamlQuery
{
ViewXml =
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='" + name + @"'/>
<Value Type='" + type + "'>" + value + @"</Value>
</Eq>
</Where>
<RowLimit>" + rowLimit + @"</RowLimit>
</Query>
</View>"
};
listItems = documentsList.GetItems(camlQuery);
ctx.Load(documentsList);
ctx.Load(listItems,
items => items.IncludeWithDefaultProperties(
item => item.DisplayName));
ctx.ExecuteQuery();
}
return listItems;
}
提前致谢
答案 0 :(得分:0)
看起来您正在尝试在文档库中配置项级别权限。如果我错了,请纠正我。
首先,您必须停止从父网站继承权限。然后,您可以创建工作流,并在上载文档时触发它。设计工作流以配置项级别的权限比在代码中执行它更容易。维护也很容易。