Convert data to another charset/codepage in vb net
ActiveX RegEdit.   ActiveX User account Manager   Pure-ASP Upload
Export MDB/DBF from ASP   Active LogFile   WebChecker   ActiveX/ASP Multi Dictionary object
 See 
 also 
 IISTracer, real-time IIS monitor and logging tool.
 Huge ASP file upload with progress bar. 



Do you like this article?
Please, rate it
and write review!
Rated:
by Aspin.com users
What do you think?
 Top messages
 22.3.2003 19:18:41 
 Read and write SQL image data, store binary file to sql table. (nbsp;WSHDatabaseConversionVBScript)
 4.5.2002 9:16:43 
 Send an email from ASP (WSH) using VBSscript, CDONTS and Outlook. (nbsp;ASP / ASP.NetWSHVBScriptEmail)
 12.6.2003 9:14:29 
 Download multiple files in one http request (nbsp;File & data transferVBScript)

 Convert data to another charset/codepage in vb net 

 Areas>ASP / ASP.Net>Functions>Conversion
 Areas>Languages>VB.Net

     Sometimes you will need to export some data from an ASP page and use another charset than the encoding you have specified in Web.config. If you have next line in web.config, all string response data from Response.Write method are converted to utf-8.

<globalization requestEncoding="utf-8" responseEncoding="utf-8" />

    You can simply change response charset and content-type with next commands:

  Response.Charset = "windows-1250"
  Response.ContentType = "text/plain" 

    But if you try to write a string data using Response.Write method, the result will confuse client side - the response data will be encoded as utf-8, but response header will have charset=windows-1250. So you have to convert the unicode data to data with windows-1250 code page. I created short function to convert such data from Unicode (VB String) to another code page (for example windows-1250). I created a simple conversion function using System.Text.Encoding:

Function EncodeString(ByRef SourceData As String, ByRef CharSet As String) As Byte()
  'get a byte pointer To the source data
  Dim bSourceData As Byte() = System.Text.Encoding.Unicode.GetBytes(SourceData)

  'get destination encoding 
  Dim OutEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(CharSet)

  'Encode the data To destination code page/charset
  Return System.Text.Encoding.Convert(System.Text.Encoding.Unicode, OutEncoding, bSourceData)
End Function

Then you can simply write:

Dim Data As string

' Fill the string variable with some data
Data = "Some string with any chars suitable For windows-1250 charset"

'Set content-type
Response.ContentType = "text/plain"
'Set out charset
Response.Charset = "windows-1250"
'Write string converted To the charset.
Response.BinaryWrite EncodeString(Data, "windows-1250")

See also CharSetConvert method of ByteArray object for similar functionality in plain ASP or WSH scripts (in VB Script, JScript).  
 

See also for 'Convert data to another charset/codepage in vb net' article:

     Convert a binary data (BinaryRead) to a string by VBS This article, demonstrates several versions of source VBS code you can use to work with binary data in ASP and convert the data to a String format.
     Create and work with binary data in ASP/VBScript Lets you convert/create binary data in ASP to use the data for BinaryWrite/BinaryRead.

If you like this page, please include next link on your pages:
<A
 Href="http://www.motobit.com/tips/detpg_convert-charset-vbnet/"
 Title="Short sample to convert String Unicode
  data to another charset/codepage using
  System.Text.Encoding"
>Convert data to another charset/codepage in vb net</A>

     IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).      ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.
     Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.      ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.
     ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.      Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.
     Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).      ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).
     WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.      HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.

© 1996 – 2010 Antonin Foller, PSTRUH Software, e-mail help@pstruh.cz