none
UWP connection to SharePoint Online RRS feed

  • Question

  • I have a Universal Windows Platform application that makes connection with O365 Tenant. When I'm trying to use this token to connect to SharePoint Online I get Exception at twinapi.appcore.dll. If I turn Common Language Runtime Exceptions, first I get

    System.IO.FileNotFoundException regarding Microsoft.SharePoint.Client.Runtime.Windows, Version=16.1.0.0

    then I get

    System.Net.WebException: 'net_servererror, 401, '

    The connection between UWP app to O365 is taken from Microsoft Example

    SharePoint CSOM connection part looks like this:

    public async Task<bool> SignInCurrentUserAsync()
    {
        var token = await AuthenticationHelper.GetTokenForUserAsync();
    
        if (token != null)
        {
            _mailAddress = (string)_settings.Values["userEmail"];
            _displayName = (string)_settings.Values["userName"];
            _token = token;
    
            using (var ctx = new Microsoft.SharePoint.Client.ClientContext("{My SharePoint Online URL}"))
            {
                ctx.ExecutingWebRequest += Context_ExecutingWebRequest;
                Web web = ctx.Web;
                ctx.Load(web);
                await ctx.ExecuteQueryAsync();
                var title = web.Title;
            }
    
            return true;
        }
        else
        {
            return false;
        }
    }
    
    void Context_ExecutingWebRequest(object sender, Microsoft.SharePoint.Client.WebRequestEventArgs e)
    {
        e.WebRequest.Headers["Authorization"] = "Bearer " + _token;
    }

    I'm pretty sure that the app permissions are set in the right way, at Application Registration Portal I have selected Graph Permissions "Sites.ReadWrite.All".

    Thursday, October 19, 2017 8:13 AM