本文整理汇总了C#中Tenant.GetSiteCollections方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.GetSiteCollections方法的具体用法?C# Tenant.GetSiteCollections怎么用?C# Tenant.GetSiteCollections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.GetSiteCollections方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//gather settings from the host process config file
string tenantName = ConfigurationManager.AppSettings["TenantName"];
string tenantUpnDomain = ConfigurationManager.AppSettings["TenantUpnDomain"];
Uri tenantAdminUri = new Uri(string.Format("https://{0}-admin.sharepoint.com", tenantName));
//get the ream and app-only access token
string adminRealm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
var adminToken = TokenHelper.GetAppOnlyAccessToken
(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, adminRealm).AccessToken;
//we use the app-only access token to authenticate without the interaction of the user
using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), adminToken))
{
//load the tenant object
var tenant = new Tenant(clientContext);
clientContext.Load(tenant);
clientContext.ExecuteQuery();
//call the extension method to get all site collections
IList<SiteEntity> siteCollections = tenant.GetSiteCollections();
//at this stage you could build aby report, like an Excel file with OpenXML
//in this demo we generate a simple email
EmailProperties emailProperties = GenerateEmailReport(siteCollections);
//use the OffideDev PnP utilities to send out the email
Utility.SendEmail(clientContext, emailProperties);
clientContext.ExecuteQuery();
}
}
示例2: GetSiteCollectionsTest
public void GetSiteCollectionsTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
var siteCols = tenant.GetSiteCollections();
Assert.IsTrue(siteCols.Any());
}
}
示例3: CheckIfSiteExistsTest
public void CheckIfSiteExistsTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext()) {
var tenant = new Tenant(tenantContext);
var siteCollections = tenant.GetSiteCollections();
var site = siteCollections.First();
var siteExists1 = tenant.CheckIfSiteExists(site.Url, "Active");
Assert.IsTrue(siteExists1);
try {
var siteExists2 = tenant.CheckIfSiteExists(site.Url + "sites/aaabbbccc", "Active");
Assert.IsFalse(siteExists2, "Invalid site returned as valid.");
}
catch (ServerException) { }
}
}
示例4: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
var tenant = new Tenant(tenantContext);
var siteCols = tenant.GetSiteCollections();
foreach (var siteCol in siteCols)
{
if (siteCol.Url.Contains(sitecollectionNamePrefix))
{
try
{
// Drop the site collection from the recycle bin
if (tenant.CheckIfSiteExists(siteCol.Url, "Recycled"))
{
tenant.DeleteSiteCollectionFromRecycleBin(siteCol.Url, false);
}
else
{
// Eat the exceptions: would occur if the site collection is already in the recycle bin.
try
{
// ensure the site collection in unlocked state before deleting
tenant.SetSiteLockState(siteCol.Url, SiteLockState.Unlock);
}
catch { }
// delete the site collection, do not use the recyle bin
tenant.DeleteSiteCollection(siteCol.Url, false);
}
}
catch (Exception ex)
{
// eat all exceptions
Console.WriteLine(ex.ToString());
}
}
}
}
示例5: FillSitesViaTenantAPIAndSearch
/// <summary>
/// Fill site list via tenant API for "regular" site collections. Search API is used for OneDrive for Business site collections
/// </summary>
/// <param name="tenant">Tenant object to operate against</param>
private void FillSitesViaTenantAPIAndSearch(Tenant tenant)
{
#if !CLIENTSDKV15
// Use tenant API to get the regular sites
var props = tenant.GetSiteCollections(includeDetail: false);
if (props.Count == 0)
{
return;
}
else
{
if (this.sites == null)
{
this.sites = new List<string>(props.Count);
}
}
foreach (var prop in props)
{
this.sites.Add(prop.Url.ToLower());
}
// Use search api to get the OneDrive sites
this.sites.AddRange(SiteSearch(tenant.Context, "contentclass:\"STS_Site\" AND WebTemplate:SPSPERS"));
#endif
}
示例6: SiteExistsTest
public void SiteExistsTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
var siteCollections = tenant.GetSiteCollections();
var site = siteCollections.First();
var siteExists1 = tenant.SiteExists(site.Url);
Assert.IsTrue(siteExists1);
var siteExists2 = tenant.SiteExists(site.Url + "sites/aaabbbccc");
Assert.IsFalse(siteExists2, "Invalid site returned as valid.");
}
}
示例7: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
var tenant = new Tenant(tenantContext);
var siteCols = tenant.GetSiteCollections();
foreach (var siteCol in siteCols)
{
if (siteCol.Url.Contains(sitecollectionNamePrefix))
{
try
{// ensure the site collection in unlocked state before deleting
tenant.SetSiteLockState(siteCol.Url, SiteLockState.Unlock);
// delete the site collection, do not use the recyle bin
tenant.DeleteSiteCollection(siteCol.Url, false);
}
catch (Exception ex)
{
// eat all exceptions
Console.WriteLine(ex.ToString());
}
}
}
}