By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,523 Members | 1,938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,523 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Feb 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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...

Feb 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.