获取用户可访问的站点列表 [英] Get List Of Sites That User Have Access To

查看:79
本文介绍了获取用户可访问的站点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,


有没有什么方法可以使用c#CSOM代码获取特定用户(不同用户)可以访问的SharePoint网站列表。


可以使用搜索。



谢谢


Anoop.KV


解决方案

您好Anoop.KV,


以下CSOM C#代码供您参考。

 public static class Program 
{

private static void GetSubSites (ClientContext siteCtx,WebCollection网站,字符串userLoginName,ref List< Web> allSites)
{
if(webs.Count> 0)
{
siteCtx.Load(webs, w => w.Include(a => a.Webs,a => a.Title,a => a.Url));
siteCtx.ExecuteQuery();
foreach(Web中的Web)
{
var permissions = web.GetUserEffectivePermissions(userLoginName);
siteCtx.ExecuteQuery();
if(permissions.Value.Has(PermissionKind.ViewPages))
{
allSites.Add(web);
}
GetSubSites(siteCtx,web.Webs,userLoginName,ref allSites);
}
siteCtx.ExecuteQuery();
}
}

static void Main(string [] args)
{
var username =" domain \\ test1" ;;
ClientContext ctx = new ClientContext(" http:// sp2013 / sites / team");
ctx.Credentials = new NetworkCredential(" admin"," xx"," domain");
var web = ctx.Web;
列表<网络> allSites = new List< Web>();
ctx.Load(web,w => w.Webs,w => w.Title,w => w.Url);
ctx.ExecuteQuery();
用户user = web.EnsureUser(用户名);
ctx.Load(用户);
ctx.ExecuteQuery();
var permissions = web.GetUserEffectivePermissions(user.LoginName);
ctx.ExecuteQuery();
if(permissions.Value.Has(PermissionKind.ViewPages))
{
allSites.Add(web);
}
GetSubSites(ctx,web.Webs,user.LoginName,ref allSites);
foreach(allSites网站)
{
Console.WriteLine(site.Title +" =>" + site.Url);
Console.WriteLine(" -------------------");
}
Console.ReadKey();
}
}

最好的问候,


Dennis



Hi Team,

Is there any way I can get the list of SharePoint sites that a specific user (different user) has access to, using c# CSOM code.

May be with Search.

Thank you

Anoop.KV

解决方案

Hi Anoop.KV,

The following CSOM C# code for your reference.

public static class Program
{
	
	private static void GetSubSites(ClientContext siteCtx, WebCollection webs,string userLoginName, ref List<Web> allSites)
	{
		if (webs.Count > 0)
		{
			siteCtx.Load(webs, w => w.Include(a => a.Webs, a => a.Title, a => a.Url));
			siteCtx.ExecuteQuery();
			foreach (Web web in webs)
			{
				var permissions = web.GetUserEffectivePermissions(userLoginName);
				siteCtx.ExecuteQuery();
				if (permissions.Value.Has(PermissionKind.ViewPages))
				{
					allSites.Add(web);
				}                    
				GetSubSites(siteCtx, web.Webs,userLoginName, ref allSites);
			}
			siteCtx.ExecuteQuery();
		}
	}

	static void  Main(string[] args)
	{
		var username = "domain\\test1";
		ClientContext ctx = new ClientContext("http://sp2013/sites/team");
		ctx.Credentials = new NetworkCredential("admin", "xx", "domain");
		var web = ctx.Web;
		List<Web> allSites = new List<Web>();
		ctx.Load(web, w => w.Webs, w => w.Title, w => w.Url);
		ctx.ExecuteQuery();
		User user = web.EnsureUser(username);
		ctx.Load(user);
		ctx.ExecuteQuery();
		var permissions = web.GetUserEffectivePermissions(user.LoginName);
		ctx.ExecuteQuery();
		if (permissions.Value.Has(PermissionKind.ViewPages))
		{
			allSites.Add(web);           
		}
		GetSubSites(ctx, web.Webs,user.LoginName, ref allSites);
		foreach (Web site in allSites)
		{
			Console.WriteLine(site.Title + " => " + site.Url);
			Console.WriteLine("-------------------");
		}
		Console.ReadKey();
	}     
} 

Best Regards,

Dennis


这篇关于获取用户可访问的站点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆