Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > write unicode data to a file

Reply
Thread Tools

write unicode data to a file

 
 
raj.sinha@gmail.com
Guest
Posts: n/a
 
      04-24-2006
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

 
Reply With Quote
 
 
 
 
Joerg Jooss
Guest
Posts: n/a
 
      04-27-2006
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
news-


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Convert unicode escape sequences to unicode in a file Jeremy Python 0 01-11-2011 11:39 PM
Convert unicode escape sequences to unicode in a file Jeremy Python 1 01-11-2011 10:36 PM
write Unicode to sys.out.write without access to sitecustomize.py Rob Knop Python 1 08-28-2009 03:22 PM
how to write unicode to a txt file? Frank Potter Python 2 01-17-2007 04:57 PM
Is that passiable to write unicode data from SQL to text file? Twopair ASP General 1 01-11-2005 03:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57