0

I have links in a SharePoint Online site page that I would like to retrieve and modify from within a C# application. I have been successful in using the SharePointPnPCoreOnline NuGet package to change links within a ClientSideText object, but I am stuck when I try to do the same with a ClientSideWebPart object. I can read the HTML (via the HtmlPropertiesData property) but I can't update it because it is a read-only property.

Any suggestions on how this can be done?

5
  • I havent tried it, but can you use GetPublicInstancePropertyValue and SetPublicInstancePropertyValue method to get the HTML content and update the link and set it back? Jun 5, 2019 at 22:49
  • I tried, but the SetPublicInstancePropertyValue method threw an exception "Property set method not found".
    – Steve
    Jun 6, 2019 at 17:43
  • Is there another way to do what I am asking? ...possibly by not using the SharePoint PnP Core library?
    – Steve
    Jun 24, 2019 at 18:30
  • Can you let me know, what you already have and what are trying to achieve using code? Maybe I can figure out another way or workaround. Jun 24, 2019 at 20:49
  • See my solution below.
    – Steve
    Oct 16, 2019 at 20:09

1 Answer 1

1

I was able to get this to work using the following steps:

  1. Get a JSON object from the ServerProcessedContent property.
JObject jsonObject = clientSideWebPart.ServerProcessedContent;
  1. Update the object with my changes.
jsonObject[@"imageSources"][@"imageURL"] = imageSourcesImageUrl;
  1. Set the PropertiesJson property to the JSON object's text (call ToString()).
string json = jsonObject.ToString();
clientSideWebPart.PropertiesJson = json;

These was certainly not intuitive. I had to read through the SharePointPnPCoreOnline library's code to understand what needed to be done.

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.