Quite new to this sharepoint.se I just go ahead an post you my code which is not working:

using (ClientContext clientContext = new ClientContext(m_WebSiteUrl))
                SecureString passWord = new SecureString();
                foreach (char c in m_password.ToCharArray()) passWord.AppendChar(c);
                System.Net.NetworkCredential xCredNetwork = null;
                Microsoft.SharePoint.Client.SharePointOnlineCredentials xCred = null;
                if (!string.IsNullOrEmpty(m_DomainName))
                    xCredNetwork = new System.Net.NetworkCredential(m_userName, m_password, m_DomainName);
                    clientContext.Credentials = xCredNetwork;
                    xCred = new SharePointOnlineCredentials(m_userName, passWord);
                    clientContext.Credentials = xCred;
                Web xWeb = clientContext.Web;

                DateTime calDate = startDate;
                List targetList = xWeb.Lists.GetByTitle(m_TargetListName);

                string strListID = targetList.Id.ToString();

                CalendarWSHelper xCalHelper = new CalendarWSHelper(xCredNetwork, clientContext.Site.RootWeb.Url, targetList.Id.ToString(), xWeb.Id.ToString()); //Here is the ERROR

I'm getting the error at clientContext.Site.RootWeb.Url telling:

The property or field 'Url' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

But this was working fine when before I added the If / Else with the password it can't be that I did there something wrong.


You have to explicitly request the RootWeb before :

Web rootWeb = clientContext.Site.RootWeb; 
clientContext.Load(rootWeb, rw => rw.Url); 

then you can use rootWeb.Url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.