sharepointsharepoint-2010sharepoint-listsharepoint-listtemplate

add html value when creating sharepoint list instance


I have created a Sharepoint list definition, and an instance of that definition. In the instance I need to store some HTML as the value of a field in my list instance. I know I can do this through the UI, but I need this list created on deployment. When I wrap my HTML value in CDATA tags, the item is simply not created. I get a deployment error if I Just have my HTML inline with my XML.

Elements.xml:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="ListName"
                    OnQuickLaunch="TRUE"
                    TemplateType="10051"
                    Url="Lists/ListName"
                    Description="List Description">

        <Data>
          <Rows>
             <Row>
                  <Field Name="Title">My Title</Field>
                  <Field Name="Value">

                    <p>Some HTML HERE</p>
                    <table border="1"; cellpadding="10";>
                      <tr style="font-family:Arial; font-size:10pt;">
                        <th>header1</th>
                        <th> ... </th>
                      </tr>
                      <tr style="font-family:Arial; font-size:8pt;">
                        <td>Vaue1</td>
                        <td> ... </td>
                      </tr>
                    </table>

                  </Field>
                </Row>
          </Rows>
        </Data>
      </ListInstance>
    </Elements>

Any help would be appreciated.


Solution

  • You need to HTML encode the value:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="ListName"
                    OnQuickLaunch="TRUE"
                    TemplateType="10051"
                    Url="Lists/ListName"
                    Description="List Description">
    
        <Data>
          <Rows>
             <Row>
                  <Field Name="Title">My Title</Field>
                  <Field Name="Value">
    
                    &lt;p&gt;Some HTML HERE&lt;/p&gt;
                    &lt;table border=&quot;1&quot;; cellpadding=&quot;10&quot;;&gt;
                      &lt;tr style=&quot;font-family:Arial; font-size:10pt;&quot;&gt;
                        &lt;th&gt;header1&lt;/th&gt;
                        &lt;th&gt; ... &lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;tr style=&quot;font-family:Arial; font-size:8pt;&quot;&gt;
                        &lt;td&gt;Vaue1&lt;/td&gt;
                        &lt;td&gt; ... &lt;/td&gt;
                      &lt;/tr&gt;
                    &lt;/table&gt;
    
                  </Field>
                </Row>
          </Rows>
        </Data>
      </ListInstance>
    </Elements>