I really need your help on this.
I would like to know how i can retrieve current user's password and login from a ClaimClientContext.GetAuthenticatedContext.
What i want :
I'm trying to code a self-provisioning exe for a customer. My customer will have to log into his Sharepoint Online tenont, and then he will have to fill a window.Forms, choosing to which subsite he wants to add a subsite, then he will enter name, url and description.
What i have :
my customer's tenant is like this : the Root. Under the Root (let's call it X), 5 (or more) subsites (calling them Y). Under each subsite, 5(or more) other subsites (calling them Z).
The client wants to create Z subsites under the Y subsites. To do this, i created the following program :
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string targetSite = ConfigurationManager.AppSettings["SpSiteURL"];
try
{
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
{
Web web = ctx.Web;
ctx.Load(web); // Query for Web
ctx.ExecuteQuery(); // Execute
//After authentication and ctx complete, run window form !
Application.Run(new createSiteParam(ctx));//run the window.forms
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.TraceError(ex.Message);
}
}
Now, in the window.forms, i have buttons, and i've their event handler, like the Click one. So when the customer clicks on the button "Create Subweb", it launches the following eventhandler :
private void btnCreate_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
/*Get all fields values*/
string siloSelected = lstSilos.SelectedItem.ToString();
string labName = txtLabName.Text;
string labUrl = txtLabUrl.Text;
string labDesc = txtLabDesc.Text;
string labInitials = txtLabInitials.Text;
string labCategory = txtLabCategory.Text;
string labYammer = txtLabYamFeed.Text;
bool doesWebExist = checkSubWebs(_ctx, siloSelected, txtLabName.Text);
if (doesWebExist == true)
{
Console.WriteLine("subsite already exists");
}
else
{
Console.WriteLine("subsite doesn't even exist");
}
Console.WriteLine("Lab Name = {0}", labName);
}
In my checkSubWebs bool, i check if the subsite already exists :
private bool checkSubWebs(ClientContext ctx, string parentName,string webTitle)
{
bool foundASiteTitle = false;
try
{
if (ctx != null)
{
Web web = ctx.Web;
ctx.Load(web, website => website.Webs, website => website.Title); // Query for Web
ctx.ExecuteQuery(); // Execute
foreach (Web orWebsite in web.Webs)
{
if (orWebsite.Title == webTitle)
{
foundASiteTitle = true;
}
}
return foundASiteTitle;
}
else
{
return foundASiteTitle;
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.TraceError(ex.Message);
return false;
}
}
Here is for my code. I've got the claimAuth code from msdn : https://code.msdn.microsoft.com/office365/Remote-Authentication-in-b7b6f43c#content
What exactly is my problem :
Now, my problem is the following : when running the programm, i don't get any "subsite already exists". I found why : because in the checkSubWebs, i stay and parse only the Y level. Not the Z.
How could i go deeper in the Z?
I should have created a new ClientContext.
BUT, I don't know how to get the current user's password and login from the AuthClaim.
So please, could you give me more advices? Maybe there are other solutions to run it, like create a new ClientContext without using user's credentials ?
Thanks a lot !!
Have a nice day and a nice Easter.