ASP.net/VB.net generating gibberish in file write.

M

Merennulli

Ok, did some seriously ugly meddling with javascript so that my user
can do a level of formatting which gets shunted into a hidden input
field as raw HTML code. That code is then passed back and written
directly to a file. This works..almost.

Problems:
70% of the time, when I click the "Create" asp:button object to
activate the script, the result is an HTML file which displays
" " in place of every " " and "â€"" in place of every
dash character. Looking at the file in notepad does not show these
mystery characters, and if I save, even without doing any editing, it
fixes the file. Obviously, the " " shows up as " " on the
screen, since the   is interpreted by the browser.
20% of the time, doing the exact same thing, only the dashes are
replaced.
10% of the time, it works perfectly, still doing the exact same thing.

I bypassed the javascript and just put the raw text of what the HTML
output should be, in a textarea. Same result, so I know it's not the
javascript.

textPassed = Request.Form("textpass")
textPassed = "<html><body>" & textPassed & "</body></html>"
Try
'write to file
Dim path = "c:\custom\" & fileName
If File.Exists(path) Then
File.Delete(path)
End If
Dim fs As IO.TextWriter = File.CreateText(path)

fs.Write(textPassed)
fs.Close()

' Open the stream and read it back.
Dim sr As StreamReader = File.OpenText(path)
Do While sr.Peek() >= 0
Console.WriteLine(sr.ReadLine())
Loop
sr.Close()

Response.Write("File Created: " & fileName)
Catch ex As Exception
Response.Write(ex.Message & "<br>" & ex.StackTrace)
End Try
 
M

Merennulli

Ok, I did a workaround, but I'm still interested if anyone knows or can
guess at what happened here.

textPassed = Request.Form("textpass")
textPassed = "<html><body>" & textPassed & "</body></html>"
textPassed = textPassed.Replace(Chr(160), "&nbsp;")
textPassed = textPassed.Replace("-", "-")

That fixes this symptom, but I still dont' know what the problem is...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top