Question

The following code is adding extra %22 after the aspx which cause link to fail.

XmlElement p = new XmlDocument().CreateElement("p");
p.InnerText = @"<table style=""width: 100%""><tbody>
                                <tr><td>&#160;<a href=" + web.Url + @"/Lists/Jr/AllItems.aspx"">J & R</a></td></tr>
                                <tr><td>&#160;<a href=" + web.Url + @"/SalesStatus/Forms/AllItems.aspx"">Sales Status</a></td></tr> </tbody></table>";
                ContentEditorWebPart cewp = new ContentEditorWebPart
                {
                    Content = p
                };
Was it helpful?

Solution

%22 is code for quote (").

This is because you forgot to add a starting quote. I mean, if, for example, web.Url is equal to http://localhost, final html will be:

<a href=http://localhost/Lists/Jr/AllItems.aspx">J & R</a>

This html is not correct, so sharepoint "fixes" it, replacing " with %20.

You should provide starting quote as well as the ending one, as follows:

p.InnerText = @"<table style=""width: 100%""><tbody>
                <tr><td>&#160;<a href=""" + web.Url + @"/Lists/Jr/AllItems.aspx"">J & R</a></td></tr>
                <tr><td>&#160;<a href=""" + web.Url + @"/SalesStatus/Forms/AllItems.aspx"">Sales Status</a></td></tr> </tbody></table>";
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top