Adding links in the CEWP
-
16-10-2019 - |
문제
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> <a href=" + web.Url + @"/Lists/Jr/AllItems.aspx"">J & R</a></td></tr>
<tr><td> <a href=" + web.Url + @"/SalesStatus/Forms/AllItems.aspx"">Sales Status</a></td></tr> </tbody></table>";
ContentEditorWebPart cewp = new ContentEditorWebPart
{
Content = p
};
해결책
%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> <a href=""" + web.Url + @"/Lists/Jr/AllItems.aspx"">J & R</a></td></tr>
<tr><td> <a href=""" + web.Url + @"/SalesStatus/Forms/AllItems.aspx"">Sales Status</a></td></tr> </tbody></table>";
제휴하지 않습니다 sharepoint.stackexchange