本文整理汇总了C#中Tenant.SiteExists方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.SiteExists方法的具体用法?C# Tenant.SiteExists怎么用?C# Tenant.SiteExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.SiteExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextSiteCollectionUrlTenant
/// <summary>
/// Returns the next site collection number
/// </summary>
/// <param name="siteDirectoryUrl">Url to the site directory site</param>
/// <returns>The next site collection Url</returns>
public string GetNextSiteCollectionUrlTenant(ClientContext cc, Web web, ClientContext ccSiteDirectory, Web webSiteDirectory, string siteDirectoryUrl, string siteDirectoryListName, string baseSiteUrl)
{
int lastNumber = GetLastSiteCollectionNumber(ccSiteDirectory, webSiteDirectory, siteDirectoryUrl, siteDirectoryListName);
lastNumber++;
string nextSiteName = DateTime.Now.ToString("yyyy") + String.Format("{0:0000}", lastNumber);
string nextUrl = String.Format("{0}{1}", baseSiteUrl, nextSiteName);
bool validUrl = false;
Tenant tenant = new Tenant(web.Context);
while (!validUrl)
{
if (!tenant.SiteExists(nextUrl))
{
validUrl = true;
}
else
{
lastNumber++;
nextSiteName = DateTime.Now.ToString("yyyy") + String.Format("{0:0000}", lastNumber);
nextUrl = String.Format("{0}{1}", baseSiteUrl, nextSiteName);
}
}
return nextUrl;
}
示例2: ProcessSiteCreationRequest
public string ProcessSiteCreationRequest(ClientContext ctx, SiteCollectionRequest siteRequest)
{
// Resolve full URL
var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", siteRequest.TenantName, siteRequest.ManagedPath, siteRequest.Url);
// Resolve the actual SP template to use
string siteTemplate = SolveActualTemplate(siteRequest);
Tenant tenant = new Tenant(ctx);
if (tenant.SiteExists(webFullUrl))
{
// Abort... can't proceed, URL taken.
throw new InvalidDataException(string.Format("site already existed with same URL as {0}. Process aborted.", webFullUrl));
}
else
{
// Create new site collection with storage limits and settings from the form
tenant.CreateSiteCollection(webFullUrl,
siteRequest.Title,
siteRequest.Owner,
siteTemplate,
(int)siteRequest.StorageMaximumLevel,
(int)(siteRequest.StorageMaximumLevel * 0.75),
siteRequest.TimeZoneId,
0,
0,
siteRequest.Lcid);
return webFullUrl;
}
}
示例3: CreateDeleteCreateSiteCollectionTest
public void CreateDeleteCreateSiteCollectionTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
//Create site collection test
string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
var siteExists = tenant.SiteExists(siteToCreateUrl);
Assert.IsTrue(siteExists, "Site collection creation failed");
//Delete site collection test: move to recycle bin
tenant.DeleteSiteCollection(siteToCreateUrl, true);
bool recycled = tenant.CheckIfSiteExists(siteToCreateUrl, "Recycled");
Assert.IsTrue(recycled, "Site collection recycling failed");
//Remove from recycle bin
tenant.DeleteSiteCollectionFromRecycleBin(siteToCreateUrl, true);
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Assert.IsFalse(siteExists2, "Site collection deletion from recycle bin failed");
//Create a site collection using the same url as the previously deleted site collection
siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
siteExists = tenant.SiteExists(siteToCreateUrl);
Assert.IsTrue(siteExists, "Second site collection creation failed");
}
}
示例4: TimerJobRunImpl
/// <summary>
/// Remove database record if the site is not existing in SharePoint
/// </summary>
/// <param name="sender">The current time job instance</param>
/// <param name="e">Time job event arguments</param>
protected override void TimerJobRunImpl(object sender, TimerJobRunEventArgs e)
{
var tenant = new Tenant(e.TenantClientContext);
bool existed = tenant.SiteExists(e.Url);
if (existed)
return;
Log.Info(TimerJobsResources.CleanUpJob_RemoveSite, e.Url);
DbRepository.UsingContext(context => {
var site = context.GetSite(e.Url);
context.Sites.Remove(site);
});
}
示例5: CreateSiteCollection
public string CreateSiteCollection()
{
var user = GetSpUser.ResolveUserById(_ctx, _actionRequest.User);
var tenant = new Tenant(_ctx);
var webUrl =
$"https://{_actionRequest.TenantName}.sharepoint.com/{_siteCollectionRequest.ManagedPath}/{_actionRequest.Name}";
if (tenant.SiteExists(webUrl))
{
// "Site already existed. Used URL - {0}"
}
else
{
var newsite = new SiteCreationProperties
{
Title = _actionRequest.Name,
Url = webUrl,
Owner = user.Email,
Template = "STS#0",
Lcid = _siteCollectionRequest.Lcid,
TimeZoneId = _siteCollectionRequest.TimeZoneId,
StorageMaximumLevel = _siteCollectionRequest.StorageMaximumLevel,
StorageWarningLevel = _siteCollectionRequest.StorageMaximumLevel,
UserCodeMaximumLevel = 0,
UserCodeWarningLevel = 0
};
SpoOperation op = tenant.CreateSite(newsite);
_ctx.Load(tenant);
_ctx.Load(op, i => i.IsComplete);
_ctx.ExecuteQuery();
var step = 0;
while (!op.IsComplete)
{
step = step + 1;
Updatehelper.UpdateProgressView($"{step} Creating site collection", _actionRequest);
Thread.Sleep(10000);
op.RefreshLoad();
_ctx.ExecuteQuery();
}
}
var site = tenant.GetSiteByUrl(webUrl);
var web = site.RootWeb;
web.Description = _actionRequest.Description;
web.Update();
_ctx.Load(web);
_ctx.ExecuteQuery();
return web.Url;
}
示例6: SiteExists
/// <summary>
/// Checks to see if a site already exists.
/// </summary>
/// <param name="siteUrl"></param>
/// <returns></returns>
public bool SiteExists(string siteUrl)
{
bool _doesSiteExist = false;
UsingContext(ctx =>
{
var tenant = new Tenant(ctx);
_doesSiteExist = tenant.SiteExists(siteUrl);
});
return _doesSiteExist;
}
示例7: CreateSiteCollection
private static void CreateSiteCollection(string template, string siteUrl)
{
// check if site exists
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
Tenant tenant = new Tenant(tenantCtx);
if (tenant.SiteExists(siteUrl))
{
Console.WriteLine("Deleting existing site {0}", siteUrl);
tenant.DeleteSiteCollection(siteUrl, false);
}
Console.WriteLine("Creating new site {0}", siteUrl);
tenant.CreateSiteCollection(new Entities.SiteEntity()
{
Lcid = 1033,
TimeZoneId = 4,
SiteOwnerLogin = (TestCommon.Credentials as SharePointOnlineCredentials).UserName,
Title = "Template Site",
Template = template,
Url = siteUrl,
}, true, true);
}
}
示例8: SetSiteLockStateTest
public void SetSiteLockStateTest()
{
try
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
tenantContext.RequestTimeout = Timeout.Infinite;
var tenant = new Tenant(tenantContext);
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
Console.WriteLine("SetSiteLockStateTest: step 1");
if (!tenant.SiteExists(siteToCreateUrl))
{
siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
Console.WriteLine("SetSiteLockStateTest: step 1.1");
var siteExists = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("SetSiteLockStateTest: step 1.2");
Assert.IsTrue(siteExists, "Site collection creation failed");
}
Console.WriteLine("SetSiteLockStateTest: step 2");
// Set Lockstate NoAccess test
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.NoAccess, true);
Console.WriteLine("SetSiteLockStateTest: step 2.1");
var siteProperties = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
Console.WriteLine("SetSiteLockStateTest: step 2.1");
tenantContext.Load(siteProperties);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties.LockState == SiteLockState.NoAccess.ToString(), "LockState wasn't set to NoAccess");
// Set Lockstate NoAccess test
Console.WriteLine("SetSiteLockStateTest: step 3");
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.Unlock, true);
Console.WriteLine("SetSiteLockStateTest: step 3.1");
var siteProperties2 = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
Console.WriteLine("SetSiteLockStateTest: step 3.2");
tenantContext.Load(siteProperties2);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties2.LockState == SiteLockState.Unlock.ToString(), "LockState wasn't set to UnLock");
//Delete site collection, also
Console.WriteLine("SetSiteLockStateTest: step 4");
tenant.DeleteSiteCollection(siteToCreateUrl, false);
Console.WriteLine("SetSiteLockStateTest: step 4.1");
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("SetSiteLockStateTest: step 4.2");
Assert.IsFalse(siteExists2, "Site collection deletion, including from recycle bin, failed");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
}
示例9: CreateDeleteSiteCollectionTest
public void CreateDeleteSiteCollectionTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
//Create site collection test
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1");
string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1.1");
var siteExists = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1.2");
Assert.IsTrue(siteExists, "Site collection creation failed");
//Delete site collection test: move to recycle bin
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2");
tenant.DeleteSiteCollection(siteToCreateUrl, true);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2.1");
bool recycled = tenant.CheckIfSiteExists(siteToCreateUrl, "Recycled");
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2.2");
Assert.IsTrue(recycled, "Site collection recycling failed");
//Remove from recycle bin
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3");
tenant.DeleteSiteCollectionFromRecycleBin(siteToCreateUrl, true);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3.1");
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3.2");
Assert.IsFalse(siteExists2, "Site collection deletion from recycle bin failed");
}
}
示例10: 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.");
}
}
示例11: CleanupCreatedTestSiteCollections
private void CleanupCreatedTestSiteCollections(ClientContext tenantContext)
{
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
String testSiteCollection = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
//Ensure the test site collection was deleted and removed from recyclebin
var tenant = new Tenant(tenantContext);
if (tenant.SiteExists(testSiteCollection))
{
tenant.DeleteSiteCollection(testSiteCollection, false);
}
}
示例12: TryDeleteSiteCollection
public void TryDeleteSiteCollection()
{
var tenant = new Tenant(_ctx);
var webUrl =
$"https://{_actionRequest.TenantName}.sharepoint.com/{_siteCollectionRequest.ManagedPath}/{_actionRequest.Name}";
if (!tenant.SiteExists(webUrl))
{
tenant.DeleteSiteCollection(webUrl, false);
}
}
示例13: ProcessBaseTemplates
private void ProcessBaseTemplates(List<BaseTemplate> templates, bool deleteSites, bool createSites)
{
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
tenantCtx.RequestTimeout = Timeout.Infinite;
Tenant tenant = new Tenant(tenantCtx);
#if !CLIENTSDKV15
if (deleteSites)
{
// First delete all template site collections when in SPO
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template);
try
{
Console.WriteLine("Deleting existing site {0}", siteUrl);
tenant.DeleteSiteCollection(siteUrl, false);
}
catch{ }
}
}
if (createSites)
{
// Create site collections
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template);
Console.WriteLine("Creating site {0}", siteUrl);
bool siteExists = false;
if (template.SubSiteTemplate.Length > 0)
{
siteExists = tenant.SiteExists(siteUrl);
}
if (!siteExists)
{
tenant.CreateSiteCollection(new Entities.SiteEntity()
{
Lcid = 1033,
TimeZoneId = 4,
SiteOwnerLogin = (TestCommon.Credentials as SharePointOnlineCredentials).UserName,
Title = "Template Site",
Template = template.Template,
Url = siteUrl,
}, false, true);
}
if (template.SubSiteTemplate.Length > 0)
{
using (ClientContext ctx = TestCommon.CreateClientContext())
{
using (var sitecolCtx = ctx.Clone(siteUrl))
{
sitecolCtx.Web.Webs.Add(new WebCreationInformation()
{
Title = string.Format("template{0}", template.SubSiteTemplate),
Language = 1033,
Url = string.Format("template{0}", template.SubSiteTemplate.Replace("#", "")),
UseSamePermissionsAsParentSite = true
});
sitecolCtx.ExecuteQueryRetry();
}
}
}
}
}
#endif
}
// Export the base templates
using (ClientContext ctx = TestCommon.CreateClientContext())
{
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template, false);
// Export the base templates
using (ClientContext cc = ctx.Clone(siteUrl))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
creationInfo.BaseTemplate = null;
// Do not extract the home page for the base templates
creationInfo.HandlersToProcess ^= Handlers.PageContents;
// Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
// blankinternet#0 as web template using CSOM/SSOM API
string templateName = template.Template;
if (template.SaveAsTemplate.Length > 0)
{
templateName = template.SaveAsTemplate;
}
ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
if (template.SubSiteTemplate.Length > 0)
//.........这里部分代码省略.........
示例14: btnCreateSite_Click
protected void btnCreateSite_Click(object sender, EventArgs e)
{
User currUser = ResolveCurrentUser();
//get the base tenant admin urls
var tenantStr = Page.Request["SPHostUrl"].ToLower().Replace("-my", "").Substring(8);
tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));
// Let's resolve the admin URL and wanted new site URL
var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", txtUrl.Text);
var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));
// Creating new app only context for the operation
string accessToken = TokenHelper.GetAppOnlyAccessToken(
TokenHelper.SharePointPrincipal,
tenantAdminUri.Authority,
TokenHelper.GetRealmFromTargetUrl(tenantAdminUri)).AccessToken;
using (var ctx = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), accessToken))
{
Tenant tenant = new Tenant(ctx);
if (tenant.SiteExists(webUrl))
{
lblStatus1.Text = string.Format("Site already existed. Used URL - {0}", webUrl);
}
else
{
// Create new site collection with some storage limts and English locale
tenant.CreateSiteCollection(webUrl, txtName.Text, currUser.Email, drpContentTypes.SelectedValue, 500, 400, 7, 7, 1, 1033);
// Let's get instance to the newly added site collection using URLs
var siteUri = new Uri(webUrl);
string token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, TokenHelper.GetRealmFromTargetUrl(new Uri(webUrl))).AccessToken;
using (var newWebContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token))
{
// Let's modify the web slightly
var newWeb = newWebContext.Web;
newWebContext.Load(newWeb);
newWebContext.ExecuteQuery();
// Let's add two document libraries to the site
newWeb.CreateDocumentLibrary("Specifications");
newWeb.CreateDocumentLibrary("Presentations");
// Let's also apply theme to the site to demonstrate how easy this is
newWeb.SetComposedLookByUrl("Characters");
}
lblStatus1.Text = string.Format("Created a new site collection to address <a href='{0}'>{1}</a>", webUrl, webUrl);
}
}
}
示例15: btnCheckUrl_Click
protected void btnCheckUrl_Click(object sender, EventArgs e)
{
User currUser = ResolveCurrentUser();
//get the base tenant admin urls
var tenantStr = Page.Request["SPHostUrl"].ToLower().Replace("-my", "").Substring(8);
tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
// Let's resolve the admin URL and wanted new site URL
var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", txtUrl.Text);
var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));
// Creating new app only context for the operation
string accessToken = TokenHelper.GetAppOnlyAccessToken(
TokenHelper.SharePointPrincipal,
tenantAdminUri.Authority,
TokenHelper.GetRealmFromTargetUrl(tenantAdminUri)).AccessToken;
using (var ctx = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), accessToken))
{
Tenant tenant = new Tenant(ctx);
if (tenant.SiteExists(webUrl))
{
lblStatus1.Text = string.Format("Site already existed. Used URL - {0}", webUrl);
}
else
{
lblStatus1.Text = string.Format("Site with given URL does not exist. Used URL - {0}", webUrl);
}
}
}