protected void btnCreate_Click(object sender, EventArgs e) { var spContext = SharePointContextProvider.Current.GetSharePointContext(Context); var clientContext = spContext.CreateUserClientContextForSPHost(); //check if we should create site collection or subsite Microsoft.SharePoint.Client.Web newWeb = null; if (Page.Request["IsDlg"].Contains("1")) { newWeb = new DeployManager().CreateSiteCollection( Page.Request["SPHostUrl"], txtUrl.Text, listSites.SelectedValue, txtTitle.Text, txtDescription.Text, clientContext, this, this.Configuration); //update the client context var newWebUri = new Uri(newWeb.Url); var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, newWebUri.Authority, TokenHelper.GetRealmFromTargetUrl(newWebUri)).AccessToken; clientContext = TokenHelper.GetClientContextWithAccessToken(newWeb.Url, token); newWeb = clientContext.Web; clientContext.Load(newWeb); clientContext.ExecuteQuery(); } else { newWeb = new DeployManager().CreateSubSite( txtUrl.Text, listSites.SelectedValue, txtTitle.Text, txtDescription.Text, clientContext, this, this.Configuration); } //Call Provision on each provisioning module foreach (Control ctrl in pnlModules.Controls) { if (ctrl is BaseProvisioningModule) { ((BaseProvisioningModule)ctrl).Provision(clientContext, newWeb); } } //dispose the clientContext clientContext.Dispose(); if (Page.Request["IsDlg"].Contains("1")) { //redirect to new site ScriptManager.RegisterClientScriptBlock(this, typeof(Default), "RedirectToSite", "navigateParent('" + newWeb.Url + "');", true); } else { // Redirect to just created site Response.Redirect(newWeb.Url); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { // The following code gets the client context that represents the host web. string contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request); // Because this is an Autohosted App, SharePoint will pass in the host Url in the querystring. // Therefore, we'll retrieve it so that we can use it in GetClientContextWithContextToken method call string hostWeb = Page.Request["SPHostUrl"]; // Then we'll build our context, exactly as implemented in the Visual Studio template for Autohosted apps clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority); // Now we will use some pretty standard CSOM operations to enumerate the // document libraries in the host web... hostingWeb = clientContext.Web; Microsoft.SharePoint.Client.ListCollection libs = hostingWeb.Lists; clientContext.Load(hostingWeb); clientContext.Load(libs); clientContext.ExecuteQuery(); bool foundLibrary = false; foreach (Microsoft.SharePoint.Client.List lib in libs) { if (lib.BaseType == Microsoft.SharePoint.Client.BaseType.DocumentLibrary) { // We know that we have at least one library, // so we'll set the foundLibrary variable to true... foundLibrary = true; // ... and add the library title to the dropdown list on the page OutputLibrary.Items.Add(lib.Title); CreateDocumentLink.CssClass = "tile tileOrange"; CreateDocumentLink.Text = "Click here to create a document\nin the selected library"; CreateDocumentLink.Enabled = true; } } SiteTitle.Text = "Office Open XML (OOXML) Document Creator: " + hostingWeb.Title; // If no libraries have been found, inform the user if (!foundLibrary) { CreateDocumentLink.CssClass = "tile tileRed"; CreateDocumentLink.Text = "There are no libraries in the host Web."; CreateDocumentLink.Enabled = false; } } }
private Microsoft.SharePoint.Client.Web GetWeb() { Microsoft.SharePoint.Client.Web web = ClientContext.Web; if (Web.Id != Guid.Empty) { web = web.GetWebById(Web.Id); } else if (!string.IsNullOrEmpty(Web.Url)) { web = web.GetWebByUrl(Web.Url); } else if (Web.Web != null) { web = Web.Web; } return(web); }
protected void Page_Load(object sender, EventArgs e) { // The following code gets the client context that represents the host web. var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request); // Because this is a provider-hosted app, SharePoint will pass in the host Url in the querystring. // Therefore, we'll retrieve it so that we can use it in GetClientContextWithContextToken method call var hostWeb = Page.Request["SPHostUrl"]; // Then we'll build our context, exactly as implemented in the Visual Studio template for provider-hosted apps using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority)) { // Now we will use some pretty standard CSOM operations to enumerate the // document libraries in the host web... Microsoft.SharePoint.Client.Web hostedWeb = clientContext.Web; Microsoft.SharePoint.Client.ListCollection libs = hostedWeb.Lists; clientContext.Load(hostedWeb); clientContext.Load(libs); clientContext.ExecuteQuery(); var foundFiles = false; foreach (Microsoft.SharePoint.Client.List lib in libs) { if (lib.BaseType == Microsoft.SharePoint.Client.BaseType.DocumentLibrary) { // ... and for each document library we'll enumerate all the Office files that // may exist in the root folder of each library. Microsoft.SharePoint.Client.Folder folder = lib.RootFolder; Microsoft.SharePoint.Client.FileCollection files = folder.Files; clientContext.Load(folder); clientContext.Load(files); clientContext.ExecuteQuery(); foreach (Microsoft.SharePoint.Client.File file in files) { if ((file.ServerRelativeUrl.ToLower().EndsWith(".docx")) || (file.ServerRelativeUrl.ToLower().EndsWith(".xlsx")) || (file.ServerRelativeUrl.ToLower().EndsWith(".pptx")) ) { // We know that we have at least one file, so we'll set the foundFiles variable to true foundFiles = true; // Then, for each Office file, we'll build a tile in the UI and set its style to an // appropriate style that we have defined in point8020metro.css. Panel fileItem = new Panel(); if (file.ServerRelativeUrl.ToLower().EndsWith(".docx")) { fileItem.CssClass = "tile tileWord fl"; } if (file.ServerRelativeUrl.ToLower().EndsWith(".xlsx")) { fileItem.CssClass = "tile tileExcel fl"; } if (file.ServerRelativeUrl.ToLower().EndsWith(".pptx")) { fileItem.CssClass = "tile tilePowerPoint fl"; } // Then we'll add text to the tile to represent the name of the file fileItem.Controls.Add(new LiteralControl(file.Name)); // And now we'll add a custom-styled link for opening the file in 'View' mode // in the Office Web Access Companion HyperLink fileView = new HyperLink(); fileView.CssClass = "tileBodyView"; fileView.Text = ""; fileView.ToolTip = "View in browser"; fileView.Target = "_blank"; fileView.Width = new Unit(125); fileView.NavigateUrl = hostedWeb.Url + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + file.ServerRelativeUrl + "&action=view&source=" + hostedWeb.Url + file.ServerRelativeUrl; // And finally we'll add a custom-styled link for opening the file in 'Edit' mode // in the Office Web Access Companion HyperLink fileEdit = new HyperLink(); fileEdit.CssClass = "tileBodyEdit"; fileEdit.Text = ""; fileEdit.ToolTip = "Edit in browser"; fileEdit.Target = "_blank"; fileEdit.Width = new Unit(125); fileEdit.NavigateUrl = hostedWeb.Url + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + file.ServerRelativeUrl + "&action=edit&source=" + hostedWeb.Url + file.ServerRelativeUrl; fileItem.Controls.Add(new LiteralControl("<br/>")); fileItem.Controls.Add(fileView); fileItem.Controls.Add(new LiteralControl("<br/>")); fileItem.Controls.Add(fileEdit); FileList.Controls.Add(fileItem); } } } } SiteTitle.Text = "Office Web Access: " + hostedWeb.Title; // If no videos have been found, build a red tile to inform the user if (!foundFiles) { LiteralControl noItems = new LiteralControl("<div id='" + Guid.NewGuid() + "' class='tile tileRed fl'>There are no Office files in the parent Web</div>"); FileList.Controls.Add(noItems); } } }
/// <summary> /// Initializes the new instance of <see cref="SPClient.SPClientWebParentPipeBind"/> class. /// </summary> /// <param name="web">the site which contains subsites.</param> public SPClientWebParentPipeBind(Microsoft.SharePoint.Client.Web web) { this.ClientObject = web; }
public override void Provision(Microsoft.SharePoint.Client.ClientContext context, Microsoft.SharePoint.Client.Web web) { //get the web's property bag var props = web.AllProperties; context.Load(props); context.ExecuteQuery(); //set the ContosoBusinessImpact property and update props["ContosoBusinessImpact"] = cboSensitivity.SelectedValue; web.Update(); context.ExecuteQuery(); //call the base base.Provision(context, web); }
private void ProcessWebProperty(Microsoft.SharePoint.Client.Web web, Definitions.PropertyDefinition property) { web.AllProperties[property.Key] = property.Value; }