2

Hey guys i am creating a runtime jnlp file for download and in that i got stuck up with the filename since it has arabic or other languages some time as the filename takes from username... when creating with that i get the file name as "اخطاء البرنامج.jnlp"

my code for creating file

Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(Server.MapPath(id & "_" & user & ".jnlp"), true)
f.write(JNLPFile)
f.close
Set f = nothing
Set fs = nothing

where "user" in the CreateTextFile is the name given by the user which may sometimes contains unicode characters or other language characters...

any solutions for this problem....?

Dinesh Ravichandran
  • 312
  • 1
  • 5
  • 16
  • What convinces you that the variable `user` contains the correct text _before_ its used in the `MapPath` and the `CreateTextFile` call? – AnthonyWJones Aug 16 '12 at 14:07
  • well the variable `user` receives the form input which is nothing but the username... so i thought it would be just a normal text and there wont be either space or special characters in it... and later on i got to know that they also want to enter other language characters... the main motive of saving the jnlp file is that the client wants the jnlp to load automatically without asking him to save or open in **`IE`** browser... so to stimulate the download i've saved the file in the server and i called it... if not there wont be an issue... – Dinesh Ravichandran Aug 17 '12 at 10:17
  • You are sure the form input value makes it to the server side variable correctly? I suspect quite strongly that it isn't. – AnthonyWJones Aug 17 '12 at 17:01
  • even i have a suspect on that... is there anything i want to mention in `
    ` tag like `unicode='UTF-8'` or something like that... can u give me a clear idea on how it is done...?
    – Dinesh Ravichandran Aug 18 '12 at 05:34
  • 1
    The bottom line is make sure all your pages are saved as UTF-8, carrying the <%@ CODEPAGE=65001 declaration and include the line `Response.CharSet="UTF-8"`. My definitive answer on this subject is found here http://stackoverflow.com/a/920405/17516 – AnthonyWJones Aug 18 '12 at 09:09

1 Answers1

1

Well, FileSystemObject does not natively support UTF8.

What you should do instead of using File System Object and CreateTextFile to build a new text file is to use ADODB Stream object.

Following is an example of a VBScript procedure that would take your path as strPath and the content of the file as strOut.

Sub Generate_File(strPath,strOut)

    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Position = 0
    objStream.Charset = "UTF-8"
    objStream.WriteText strOut
    objStream.SaveToFile server.mappath(strPath),2
    objStream.Close

End Sub