Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式对上载的sharepoint文档应用权限_C#_.net_.net 3.5_Sharepoint 2010 - Fatal编程技术网

C# 以编程方式对上载的sharepoint文档应用权限

C# 以编程方式对上载的sharepoint文档应用权限,c#,.net,.net-3.5,sharepoint-2010,C#,.net,.net 3.5,Sharepoint 2010,我正在开发一个从sharepoint检索文件的界面。我使用以下方法上载文档: public bool UploadDocument(string document) { if (String.IsNullOrEmpty(Path.GetFullPath(document))) { return false; } var site = GetNewDataContext(SiteUrl);

我正在开发一个从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;
    }
但是,我的下一步是应用自定义权限。。我在网上找到了一些博客,展示了如何做到这一点:

  • 是否可以在上载过程中设置权限
  • 我的理解是,当文件上传时,它继承了其上传到的列表中的权限
  • 我当前的下载方法返回一个ListItem。。是否可以将ListItem强制转换为SPListItem?返回SpListItem的原因是我在上面发布的博客。。SPListItem似乎包含我[中断并应用新权限]所需的权限信息
我的下载方法返回一个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;
    }
私有静态ListItemCollection GetListItemCollectionFromSp(字符串文档ListName、字符串名称、字符串值、字符串类型、int rowLimit)
{
ListItemCollection listItems=null;
使用(var ctx=GetNewContext())
{
var documentsList=ctx.Web.Lists.GetByTitle(documentListName);
var camlQuery=新的camlQuery
{
ViewXml=
@"
“+值+@”
“+行限制+@”
"
};
listItems=documentsList.GetItems(camlQuery);
ctx.Load(文件列表);
ctx.Load(列表项,
items=>items.IncludeWithDefaultProperties(
item=>item.DisplayName));
ctx.ExecuteQuery();
}
返回列表项;
}

提前感谢

看起来您正在尝试在文档库中配置项目级权限。如果我错了,请纠正我

首先,您必须停止从父站点继承权限。然后,您可以创建一个工作流,并在上载文档时触发它。设计一个工作流在项目级别配置权限比在代码中配置权限更容易。维护也很容易