3

So In my sharepoint site contents page i have an application. Can anyone tell me how to get the instance id of it. so that i can invoke the link :

http://testingwebcompany.sharepoint.com/_layouts/15/appredirect.aspx?instance_id={ <>}

I can't seem to get it when I'm searching ClientContext.Web.Lists.

Thanks

user2526202
  • 39
  • 1
  • 2

2 Answers2

0

I got it, it seems that the instance id is auto generated. the real url of the application is located when looping through ClientContext.Web.Webs[].Title == "Application Name" then retrieving the ClientContext.Web.Webs[].Url.

user2526202
  • 39
  • 1
  • 2
0

The following example demonstrates how to retrieve an App by its title

public static class WebExtensions
{

    public static IEnumerable<AppInstance> GetAppInstanceByTitle(this Web web,string appTitle)
    {
        var ctx = web.Context;
        var apps = AppCatalog.GetAppInstances(ctx, web);
        var result = ctx.LoadQuery(apps.Where(a => a.Title == appTitle));
        return result;
    }
}

Usage

using (var ctx = new ClientContext(webUri))
{
    var appTitle = "\"Napa\" Office 365 Development Tools";
    var result = ctx.Web.GetAppInstanceByTitle(appTitle);
    ctx.ExecuteQuery();
    var app = result.FirstOrDefault();
    if (app != null) Console.WriteLine(app.Id); // print App Instance Id
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • In Powershell CSOM how do we do this? `$result = $web.GetAppInstanceByTitle($appTitle)` Here I am getting error. Any extra dll we need to load other than `Microsoft.SharePoint.Client.dll` and `Microsoft.SharePoint.Client.Runtime.dll`? – Harsh Jaswal Aug 08 '18 at 06:58