Hi Expert,
Until now, I am a little confusing on the Client Context of the SharePoint Online. I can get the context by using the following solutions. what is different between the two methods. and how should I choose the correct method to get client context at the right time.?
one is as below: (To be honest, sometime I can get the context but sometimes cannot ... till now mycontextTokenString is stillnull).
string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request); _contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority); _sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]); _realm = TokenHelper.GetRealmFromTargetUrl(_sharepointUrl); var _responseToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, _sharepointUrl.Authority, _realm);
TokenHelper.GetClientContextWithAccessToken(_sharepointUrl.ToString(), _responseToken.AccessToken)
another is:
var _spContext = SharePointContextProvider.Current.GetSharePointContext(Context); var _clientContext = _spContext.CreateUserClientContextForSPHost()
Hi there, if you found my comment very helpful then please | Propose as answer | . Thanks and Regards.