encoding 737 confused - vb.net

I am using VB .Net 2008
Why is my conversion from ASCII to 737 (Greek DOS) with the Encoding.Convert command returning readable characters, while an IO.StreamWriter with Encoding.GetEncoding(737) writes a file with non-readable characters?
I am asking this because I want to send row data to a printer which can print Greek as 737.
If I send the result of Encoding.Covert, I get the wrong result, while If I write a file as above and copy it to the printer is ok

Use the GetEncoding method
Dim enc As Encoding = Encoding.GetEncoding(737)
Dim fs As FileStream
fs = File.OpenRead("\737dos.txt")
Dim sr As StreamReader = New StreamReader(fs, enc)

Related

how to set byte value in vb.net above 2gb file

I have 2gb above file that file store in file stream using byte, i got the error
"Arithmetic operation resulted in an overflow."
I need to store large file above 2gb.
using this code
Dim fs As System.IO.FileStream
fs = File.Open(fpath, FileMode.Open, FileAccess.Read, FileShare.None)
Dim filelen As Long = fs.Length
Dim buffer(fs.Length - 1) As Byte
fs.Read(buffer, 0, filelen)
fs.Close()
My guess: you are initiating a variable array but the size of the array is over-limit, which would make sense if you are loading a file > 2 Gb to memory (why ?). Check the section "Length Limits" on this page. What you are doing sounds like an awful idea which could even cripple your computer. Instead you should implement some form of streaming, reading the file in smaller chunks.

System.IO.StreamReader returns corrupted output

The below given code is returning corrupted data to the variable 'mystr'
like
PK ! ��fѲ �  [Content_Types].xml �(� �UMk�#���^��N%�9�ɱ
It was reading the word files correctly. Suddenly it started happening without any change in code or software versions or source files!! Any word file I try to run through the below code gives the same corrupted output. I'm able to open the file in MsWord without any issue.
Dim myStreamReader As System.IO.StreamReader
Dim myStr As String
myStreamReader = System.IO.File.OpenText("c:\test.docx")
myStr = myStreamReader.ReadToEnd()
myStreamReader.Close()
Any suggestions why it is happening ?
You can't read a Word document using the StreamReader class as the file itself isn't plain text (it contains the data you find 'corrupted').
This link will help you reading text from a Word document.

Issues with VB and Aspose

I have the following lines of code:
Dim ms As New MemoryStream(my_memory_stream)
workbook As New Workbook(ms)
workbook.Save("C:\book1.xlsx")
My purpose is to save the stream contained in my_memory_stream into an xlsx file named "book1": the problem is that when I run this code an exception occurr (Invalid Excel2007Xlsx file format).
Does anyone know what I'm doing wrong?
Thanks so much!
Most probably, the problem is the base64 format. It is in the form of ASCII characters. You need to convert the Base64 data to binary. And then load the binary data in Workbook class.
' Decode base64
Dim binaryBytes As Byte() = Convert.FromBase64CharArray(base64Data, 0, base64Data.Length)
' Load in MemoryStream
Dim binaryStream As New MemoryStream(binaryBytes)
' Pass memory stream to Workbook
Dim workbook As New Aspose.Cells.Workbook(my_memory_stream)
workbook.Save(dataDir + "workbook-out.xlsx")
Also note that, if your decoding is correct, you can directly save the binary byte or stream to disk and verify that the Excel is saved correctly.
PS. I am a Developer Evangelist at Aspose.
It seems that you are trying to save a stream directly to a Excel file. Excel files have a fixed format, and the stream will not be adhering to the standard file protocol of excel.
I think you would like to use Workbook object of Microsoft.office.Interop.Excel namespace.

VB.net will not read text file correctly

I've been trying to use StreamReader to read a log file. I cannot verify what it is encoded in, as when I open it in notepad++ and select ANSI encoding, I get this result:
I'm getting the characters needed when using ANSI but they are followed by things like [NULL][EOT][SOH][NUL][SI]
When I try and read the file in VB (using StreamReader or ReadAll) with ANSI encoding selected the resulting string I get back is completely wrong.
How could I read a file like this in VB.net?
You could use the IO.File.ReadAllText("File Location", encoding as System.Text.Encoding) method,
Dim textFromFile as string = IO.File.ReadAllText("C:\Users\Jason\Desktop\login20130417.rdb", System.Text.Encoding.ASCII) 'Or Unicode, UFT32, UFT8, UFT7, BigEndianUnicode or default. Default is ANSI.
If you still don't get the text you need by using the default encoding (ANSI), then you can always try the other 6 different encoding methods.
Update...
It appears that your file is corrupt, using the code below I was able to get a binary representation of whatever is in the file, I got this,
1111111111111101000001110000010000000000000001010000000000010011000000000000100000000000000111100000000000100110000000000011100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111110100000111000001000000000000000101000000000001001100000000000010000000000000011110000000000010100000000000111111111111110100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
The massive amount of null data would suggest that the file is corrupt, which would also explain why we are not getting a lot of data whenever we try to read the file.
The code,
Dim fileData As String = IO.File.ReadAllText("C:\Users\Jason\Desktop\login20130417.rdb")
Dim i As Integer = 0
Dim binaryData As String = ""
Dim ch As String = ""
Do Until i = fileData.Length
ch = fileData.Chars(i)
bin = bin & System.Convert.ToString(AscW(ch), 2).PadLeft(8, "0")
i = i + 1
Loop
As #Daniel A. White suggested in his comment, that file does not appear to be encoded like a "normal" text file. A StreamReader will not work in this situation. I would attempt to use a BinaryReader.
Rdb file? Never heard of it. Quick google makes it less clear - n64 database file, Darkbot, etc...
However considering the name you have, and the general look of the opened file, i would say its a binary file.
If you want to read the file in vb.net you'll need a library of sorts, and i can't help you with one until you are able to shed some light on what the file may be, or what it was created with.

Encoding to be used for ANSI - vb.net

What encoding we need to use to save a file as text file(of type ANSI) - While saving the text file ANSI encoding to be used.
What to be used here, not seeing ANSI as an option
vb.net code - what should be given after Encoding.?
My.Computer.FileSystem.WriteAllText("d:\binary.txt", strTemp, True,System.Text.Encoding.
ANSI is not an encoding, it is just a generic name for "not Unicode". You typically use Encoding.Default, the same code page as the one your operating system uses. At least all of the programs that run on that machine can read the file without trouble.
it works for me:
System.Text.Encoding.ASCII
Use a stream writer with System encoding as default:
Dim myfilepath as String = "C:/"
Dim myappendingoption as boolean = True 'True: append text to file, False: overwrite
Dim sw As StreamWriter = New StreamWriter(myfilepath, myappendingoption, System.Text.Encoding.Default)
sw.Write("sometext")
sw.Close()