M
Marta Pia
Hello,
I'm using C# to write an html based report using keywords stored in a
database whose input I don't control. Before sending the strings to
HTML, I run them through the HttpUtility.HtmlEncode(strIn) function to
prevent my html from acting funny. Today the following error popped
up: " An unexpected exception occurred
System.ArgumentException: Found a low surrogate char without a
preceding high surrogate at index: 640. The input may not be in this
encoding, or may not contain valid Unicode (UTF-16) characters."
Any ideas? Is there anyway to to an HtmlEncode with UTF-8 bit?
Here is the affected code...
bResult = CommonUtil.EncodeForHTML (strKeywords, ref strConvert);
if (bResult) strKeywords = strConvert;
if (strKeywords.Length >1)
{
strDetail += "<TR><TH> <DIV class=HF> Keywords </DIV></TH>\r\n";
strDetail += "<TD colspan = 7> <DIV class= DF>" + strKeywords +
"</DIV></TD> </TR>\r\n";
}
fReport.WriteLine(strDetail); <<< WHERE ERROR OCCURS
public static bool EncodeForHTML(string strIn, ref string strOut)
{
try
{
if (strIn.Length < 1) return false;
strOut = HttpUtility.HtmlEncode(strIn);
return true;
}
catch
{
return false;
}
Thank you,
Marta
I'm using C# to write an html based report using keywords stored in a
database whose input I don't control. Before sending the strings to
HTML, I run them through the HttpUtility.HtmlEncode(strIn) function to
prevent my html from acting funny. Today the following error popped
up: " An unexpected exception occurred
System.ArgumentException: Found a low surrogate char without a
preceding high surrogate at index: 640. The input may not be in this
encoding, or may not contain valid Unicode (UTF-16) characters."
Any ideas? Is there anyway to to an HtmlEncode with UTF-8 bit?
Here is the affected code...
bResult = CommonUtil.EncodeForHTML (strKeywords, ref strConvert);
if (bResult) strKeywords = strConvert;
if (strKeywords.Length >1)
{
strDetail += "<TR><TH> <DIV class=HF> Keywords </DIV></TH>\r\n";
strDetail += "<TD colspan = 7> <DIV class= DF>" + strKeywords +
"</DIV></TD> </TR>\r\n";
}
fReport.WriteLine(strDetail); <<< WHERE ERROR OCCURS
public static bool EncodeForHTML(string strIn, ref string strOut)
{
try
{
if (strIn.Length < 1) return false;
strOut = HttpUtility.HtmlEncode(strIn);
return true;
}
catch
{
return false;
}
Thank you,
Marta