2

In our application, we are using SharePoint wiki library loosely as a content management system. Through custom code, I retrieve the contents of the wiki library along with its properties.

        var array = new List<object>();
        MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper("https://mysharepointsite.com", "myusername", "mypassword");
        using (ClientContext context = new ClientContext("mylocation"))
        {
            context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
            Web web = context.Web;
            ListCollection lists = web.Lists;
            List selectedList = lists.GetByTitle("mylistname");
            CamlQuery query = CamlQuery.CreateAllItemsQuery();
            ListItemCollection items = selectedList.GetItems(query);
            context.Load(items);
            context.ExecuteQuery();
            foreach (ListItem listItem in items)
            {   
                array.Add(new
                {
                    sharepointid = listItem["ID"].ToString(),
                    wikicontent = Convert.ToString(listItem["WikiField"] as object),
                });
            }
        }
        return array;

The wikicontent comes back with the HTML, problem is, it doesnt have all of the style information associated with it. So the HTML does not look like how it looks in the wiki.

Content in Wiki

Wiki Content

Content from retrieved HTML

Content from retrieved HTML

The actual HTML that I get from the code above looks like

<div class="ExternalClass7A473DBC7A6C41109A4FC8978BF5BDD9">
<table id="layoutsTable" style="width&#58;100%;">
      <tbody>
         <tr style="vertical-align&#58;top;">
            <td style="width&#58;100%;">
               <div class="ms-rte-layoutszone-outer" style="width&#58;100%;">
                  <div class="ms-rte-layoutszone-inner" role="textbox" aria-autocomplete="both" aria-haspopup="true" aria-multiline="true">
                     <h1>​​​This is a test page<br></h1>
                     <p><br></p>
                     <p>... and <span class="ms-rteFontSize-3">this </span>is a test <span class="ms-rteFontSize-6">content</span>, that has been <span class="ms-rteFontFace-7">formatted</span>.&#160;<br></p>
                     <br>
                  </div>
               </div>
            </td>
         </tr>
      </tbody>
   </table>
   <span id="layoutsData" style="display&#58;none;">false,false,1</span>
</div>

How do I get the proper formatting information?

  • After you get the html from your code, where are you displaying/rendering it? Is it within a SharePoint site or a non-SharePoint site? – Mike Lutge Aug 19 '14 at 20:50
  • It is in a non-SharePoint site. I do wrap this content into a proper HTML, head and body tags. If there is some css that needs to be referenced, I can add that in as well, just so that it can be displayed outside of SharePoint properly. – etrast81 Aug 20 '14 at 1:52
  • Okay - so I searched for one of the class that is used in the HTML - ms-rteFontSize-3 and got some css online. When I include that in my HTML, the sizes are coming up fine now. But the colors and font types are still not coming. They are not even there in the HTML, which is very surprising. How does SP store this and show it back?! – etrast81 Aug 20 '14 at 8:10
1

It seems you are getting the proper wiki page content but you are missing styles defined in SharePoint CSS files as you mentioned earlier.

In SharePoint 2013 the specified styles are declared in file: /_layouts/15/1033/styles/corev15.css

  • This is great. Thank you very very much. I am now getting the font size and type, but the color is not coming through. Any ideas? – etrast81 Aug 20 '14 at 16:05
  • Good to know :) – Vadim Gremyachev Aug 20 '14 at 16:07

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.