I am implementing a new authentication method according to the version of SharePoint in my .NET code, which may vary between the URL. However, I am unsure of how to declare an empty ClientContext
variable.
Below is my code snippet:
Uri lUri = new Uri(pSiteUrl);
//To declare an empty ClientContext variable here//
if (pSiteUrl.StartsWith(ConfigurationManager.AppSettings["New_URL"]))
{
ClientContext lClientContext = SPOClientContext.GetAuthenticatedContext(pSiteUrl);
}
else
{
ClientContext lClientContext = new ClientContext(pSiteUrl);
}
//lClientContext does not exists if it is not initialised outside the if-else statement above
Folder lRootFolder = lClientContext.Web.GetFolderByServerRelativeUrl(lUri.AbsolutePath + pFolderPath);