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
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