I am using the below part of code in provider hosted app:

                Microsoft.SharePoint.Client.File destinationFile = destinationFolder.Files.Add(fileCreationInfo);
                ListItem item = destinationFile.ListItemAllFields;
                item["AssignedTo"] = "Test 1";
                destinationContext.Load(destinationFile, k => k.ServerRelativeUrl);

                relativeUrl = destinationFile.ServerRelativeUrl;

destinationFolder and destinationContext are already loaded properly. But still I am getting the following error:

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

The weird part is, I am not able to reproduce this error in my dev environment. Can anyone help?

1 Answer 1

  1. Try loading ALL the fields. Chances are there is a calculated value or alike that has some dependency on another field. After seeing if that solves the problem, you can work it out one by one to only load the necessary fields.

  2. Try loading the item's context and invoking ExecuteQuery BEFORE updating, checking the values for the fields that are throwing the errors, and only then do the update and invoke ExecuteQuery a 2nd time.

  • 1
    I tried point 2 and it worked, though I have no idea why? The same code is working in 2 different environments. Infact, I tried this code in console app in erroneous environment and there it worked but not in provider hosted app. So no clue, but thanks for the suggestion.
    – Garima
    Feb 5, 2015 at 10:38

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.