write unicode data to a file

Discussion in 'ASP .Net' started by raj.sinha@gmail.com, Apr 24, 2006.

  1. Guest

    I have to "PUT" data to a Unicode file... a file that has the "FF FE"
    mark at the beginning of the file.

    How do i do that. What HTTP header do i need to send so that the data
    is stored in the Unicode file. Right now when i "PUT" the data it sores

    it in a regular file.


    Test code below


    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")


    ' Opens the connection to the remote server.
    xml.Open "PUT", "http://135.8.63.61/outlook/save.txt", False


    ' Try these headers
    'xml.setRequestHeader "Charset", "UTF-16"
    'xml.setRequestHeader "Charset", "text/html; charset=UTF-16"


    ' Actually Sends the request and returns the data:
    xml.Send "hello"


    If xml.Status >= 400 And xml.Status <= 599 Then
    Response.Write "Error Occurred : " & xml.Status & " - " &
    xml.statusText
    Else
    Response.Write xml.ResponseText
    End If


    Set xml = nothing
     
    , Apr 24, 2006
    #1
    1. Advertising

  2. Joerg Jooss Guest

    Thus wrote ,

    > I have to "PUT" data to a Unicode file... a file that has the "FF FE"
    > mark at the beginning of the file.
    >
    > How do i do that. What HTTP header do i need to send so that the data
    > is stored in the Unicode file. Right now when i "PUT" the data it
    > sores
    >
    > it in a regular file.
    >
    > Test code below
    >
    > Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    >
    > ' Opens the connection to the remote server.
    > xml.Open "PUT", "http://135.8.63.61/outlook/save.txt", False
    > ' Try these headers
    > 'xml.setRequestHeader "Charset", "UTF-16"
    > 'xml.setRequestHeader "Charset", "text/html; charset=UTF-16"
    > ' Actually Sends the request and returns the data: xml.Send "hello"
    >
    > If xml.Status >= 400 And xml.Status <= 599 Then
    > Response.Write "Error Occurred : " & xml.Status & " - " &
    > xml.statusText
    > Else
    > Response.Write xml.ResponseText
    > End If
    > Set xml = nothing


    If you ask this question in a .NET newsgroup one has to wonder why you don't
    use .NET? Here's a simple implementation:

    public static void DoPut(Uri uri, string fileName, Encoding encoding) {
    WebClient client = new WebClient();
    using(Stream istream = new FileStream(fileName, FileMode.Open))

    using(Stream ostream = client.OpenWrite(uri, "PUT")) {
    byte[] buffer = new byte[4096];
    int bytes;
    while((bytes = istream.Read(buffer, 0, buffer.Length)) > 0) {
    ostream.Write(buffer, 0, bytes);
    }
    }
    }

    To PUT a Unicode (UTF-16LE) file, call
    DoPut(new Uri("http://host/path/to/file.txt"), @"X:\Path\To\File.txt", Encoding.Unicode);

    Cheers,
    --
    Joerg Jooss
     
    Joerg Jooss, Apr 27, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Knop
    Replies:
    1
    Views:
    288
  2. Jeremy
    Replies:
    1
    Views:
    810
    Alex Willmer
    Jan 11, 2011
  3. Jeremy
    Replies:
    0
    Views:
    579
    Jeremy
    Jan 11, 2011
  4. Twopair
    Replies:
    1
    Views:
    159
    Mark Schupp
    Jan 11, 2005
  5. Replies:
    5
    Views:
    86
    Chris Angelico
    May 14, 2014
Loading...

Share This Page