public ActionResult Create(FormCollection collection) { try { AppWebHelper hlp = new AppWebHelper( HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string); hlp.AddAdministrator(collection["LoginName"] as string); return View("Index", hlp.GetAdministrators()); } catch (Exception ex) { LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error); throw; } }
/// <summary> /// The RER are a little buggy. Depending on the event triggered, using this: /// TokenHelper.CreateAppEventClientContext(properties, true) returns a null appweb although the /// app web exists...Therefore, as I know the name of my App and since the AppWeb's url corresponds to it /// I assume that the default appweb location is https://hostweb/appweb. This isn't valid when the App is deployed /// trough the AppCatalog. That's why I record the URL of the AppCatalog in case the App gets installed in the /// AppCatalog since this info isn't available from CSOM. /// </summary> /// <param name="properties"></param> void AppInstalled(SPRemoteEventProperties properties) { LogHelper.Log("The application was installed on "+properties.AppEventProperties.HostWebFullUrl); using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, false)) { ctx.Load(ctx.Web); ctx.Load(ctx.Web.CurrentUser); ctx.ExecuteQuery(); if(ctx.Web.WebTemplate == Constants.AppCatalogTemplate) { LogHelper.Log("Writing app catalog url", LogSeverity.Error); using(StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/App_Data/AppCataLog.xml"))) { sw.Write(ctx.Web.Url); } } AppWebHelper hlp = new AppWebHelper(properties.AppEventProperties.AppWebFullUrl.AbsoluteUri, true); hlp.AddAdministrator(ctx.Web.CurrentUser.LoginName); } }