Type25
asked on
Convert characters to web safe
I'm taking some input from the user using a standard <asp:textbox...
I'm creating a textfile from the contents of the textbox and save it as .html. This works fine, however if the user enters some dodgy characters, such as this: “cover story.”
This turns the html into looking like this: “cover story.â€
If i open the file up in notepad and then save it all is fixed.
How can i get around this issue?
I'm creating a textfile from the contents of the textbox and save it as .html. This works fine, however if the user enters some dodgy characters, such as this: “cover story.”
This turns the html into looking like this: “cover story.â€
If i open the file up in notepad and then save it all is fixed.
How can i get around this issue?
Can you show the code you are using to write to file? It sounds like a problem with the Encoding.
ASKER
Excuse the formatting
do{
int randNumber = RandomNumber(minRand, maxRand);
htmlFilename = randNumber + "_article.html";
if (!File.Exists(articleLocation + htmlFilename))
{
// Create HTML File
TextWriter tw = new StreamWriter(articleLocation + htmlFilename);
tw.WriteLine(@"<html><title>" + articleTitle + "</title>");
tw.WriteLine(@"<meta name=""apple-mobile-web-app-capable"" content=""yes""><meta name = ""viewport"" content = ""initial-scale = 1.0, user-scalable = no"">");
tw.WriteLine(@"<style>body { width:310px; } .copy {font-family:Calibri,Arial; font-size:16px;background:url(../MagWatermarks/" + customerName + ".gif); }h2 {font-family:Arial,Calibri;font-size:26px; font-weight:none; } .caption {color:Gray;font-size:13px;font-family:Arial;}</style>");
tw.WriteLine(@"<h2>" + articleTitle + "</h2>");
tw.WriteLine(@"<img src='" + picLocation + "iphone-" + articleImageURL + "' style='padding-left:2px'>");
tw.WriteLine(@"<span class=caption>" + caption + "</span>");
tw.WriteLine(@"<br><br><div class=copy>" + articleCopy + "</span>");
tw.WriteLine(@"<div style=""font-family:Calibri;width:304;height:30px;background:WhiteSmoke;padding-top:4px;font-family:Calibri;text-align:center""><a href='" + linkURL + "'>" + linkName + "</a></div>");
tw.Close();
done = true;
}
}
while (!done);
Again, I do not have any problems with encoding in this code.
What exactly causes encoding error (articleTiitle, caption, etc)? How do you get those values?
What exactly causes encoding error (articleTiitle, caption, etc)? How do you get those values?
ASKER
It's articleCopy but i would presume it's the same for all of them.
ArticleCopy is the only text field that is multiline if that makes any difference.. ?
Retrieve the field like normal, articleCopy.Text
ArticleCopy is the only text field that is multiline if that makes any difference.. ?
Retrieve the field like normal, articleCopy.Text
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Spot on!
Yes, that should work - File.CreateText do same thing about encoding.
using (StreamWriter writer = File.CreateText(Server.Map
writer.WriteLine(TextBox1.
You will not receive encoding problems.
So, what is the way you are saving textbox text?