I am developing in a Winforms .NET 4.0 project, using a WebControl as a WYSIWYG editor - working from the YARTE editor developed by Matt Groves.
I am trying to add an anchor tag and set the href attribute to the following path:
var path = http://someurl.aspx?param1="val1"¶m2="val2"¶m3="youGetTheIdea"
I have tried several approaches; I always get HTML-escaped ampersands when I try to write the url to the document:
http://someurl.aspx?param1="this"&param2="doesnt"&param3="work"
Approaches I Have Tried Unsuccessfully:
Creating the Link
webBrowser.ExecCommand("CreateLink", false, path)
Creating the HTML and pasting it in:
var htmlDocument2 = args.Document.DomDocument as IHTMLDocument2;
if (htmlDocument2 == null) return;
var range = htmlDocument2.selection.createRange() as IHTMLTxtRange;
if (range == null) return;
range.pasteHTML(string.Format(path, range.text));
Creating a file and directing the webBrowser to it:
// assume the links are already inserted, but aren't right.
var textWithBadLinks = webBrowser.DocumentText;
var betterText = UseRegexToReplaceBadLinkText(textWithBadLinks);
using (StreamWriter outfile =new StreamWriter(@"c:\test.html"))
{
outfile.Write(betterText);
}
webBrowser.Url= new Uri(@"c:\test.html");
Creating a stream and directing the webBrowser to it:
// same as above, but instead of the URL, use the DocumentStream:
webBrowser.DocumentStream = new StreamWriter(@c:\test.html);
Navigating to the file:
webBrowser.Navigate(new Uri(@"c:\test.html"))
Regardless of the approach I choose, the ampersands get escaped the links don't work.
Thank you in advance for any assistance.
Technically speaking, XHTML requires & to be valid. See: XHTML and & (Ampersand) encoding