Serializing Collections To Binary File?
Mar 17, 2011How to serialize a collection to a binary file?
Structure MainServerInfo
Dim Name As String
Dim IP As String
Dim Uname As String
Dim Pass As String
End Structure
[Code] .....
How to serialize a collection to a binary file?
Structure MainServerInfo
Dim Name As String
Dim IP As String
Dim Uname As String
Dim Pass As String
End Structure
[Code] .....
I'm developing a program that captures a bunch of information entered by a user on a tab form into five different structured arrays. I want the data to be saved into a single file and reloaded by the program into a similarly built series of structured arrays through a different form.If I understand the process of serializing collections right, I create a single ArrayList variable to capture each of the five Structured arrays.[code]
1. Do I have to declare one variable of the same type as the one in the first element of the ArrayList, or does having the public variable declared in the Class that's going to take this information already cover that?
2. Once I deserialize into the newly declared Rules ArrayList in the new form, is it a simple matter of setting the duplicated variables in the new form equal to the relevant element in the ArrayList? For example, if I have a new Public Roster As RosterDesc variable declared, can I set it equal to Rules(0) and it would automatically populate every element in the same order as they were created in the original form?
i have a complex object that holds a WPF Canvas with many child canvases, rectangles and, lines. The object includes some home grown classes as well. The main object and the home grown classes have the <Serializable()> attribute set. I tried the general formatter.Serialize(strm, rb_x) to serialize the object to a memory stream. I then found out that WPF classes are set as serializable. So after some research I discovered the System.Runtime.Serialization and found a generic Serialization Surrogate.So after some debugging I was able to serialize the object to a memory stream then copied the stream to an array of bytes then store that array in an OLE field in an MS Access table.
When I read back the access record and copy the OLE field byte array back to a memory stream and then de-serialize it back to the object I get a SerializationException "Error binding to target method."
So question #1 - is what I am trying even possible?Question #2, (assuming #1 is yes) do I need to do something special with WPF Baml type objects.
I used the ideas from this post to create a custom collection of my custom class, so that I would be able to easily sort my collection. My project uses binary serialization to save everything (well the important stuff anyway) to a file. The problem is that my custom collection now breaks the serialization.I can't seem to figure out how to get the custom collection to serialize![code]
View 10 RepliesI am trying to create a load and save function for my customizable Menu/Tool/StatusStrip controls (see signature). Those three controls use a single AppearanceControl class, which is mainly just a large list of properties (Colors) which control the colors of the Menu/Tool/StatusStrip.
I want to be able to save and load the values of these properties so the user can store them and load others with ease. Serialization seemed the obvious answer, although I never used it before.
Now, there is a slight problem that I cannot serialize Colors, so I simply gave each Color property the XmlIgnore attribute, and created an Integer property that gets and sets the Color property (using Color.ToArgb and Color.FromArgb). This way I can serialize the color properties succesfully.
Then, there is another problem. The properties are not all in the AppearanceControl class. Instead, the AppearanceControl class has a large number of subclasses, which in turn contain the color properties.
As a small example, I may have this:
vb.net
Public Class AppearanceControl
Private _toolStripColorProperties As ToolStripColorProperties
Private _menuStripColorProperties As MenuStripColorProperties
[Code]....
I am having problems with serializing and de serializing my objects.The following is my code for serializing buttons and labels which I have in my form.
Dim nodes As New List(Of nodeclass)
Dim objStreamWriter As New StreamWriter(filelocation)
For Each btn As Button In myNodeBtns
Dim u As New nodeclass
[code].....
I get an error: There is an error in XML document (20, 3).Now I have found out that this is because I have 2 root elements and 2 xml declerations. When I save the xml for the button and te xml for the label in 2 different files, I have no problem. However I have no idea how to go about saving the xml for both of them in the same file and deserializing it back.
I'm having a problem with this code in the highlighted line(*); getting the error in the heading.
Dim htmlarraylist As New List(Of iTextSharp.text.IElement)
htmlarraylist = *HTMLWorker.ParseToList(New StreamReader(tempFile), New StyleSheet())*
[Code].....
[code]...
What's really the point in using the former?It's hard to use linq if I used the former. I have to convert that to an array first which is difficult because there is no (asarray) function.I think I would change all of my code that's using System.
Collections.Specialized.StringCollection to System.Collections.Generic.List(Of String)
I want to write a generic file saving routine where the routine is passed data in the form of a collection and it sets a containsStructure flag. I wanted to be able to save the data from the collection, but if it is a collection of structures I want to be able to extract the data from the structure to write to the file.
The only trouble is, that I cannot do something like:
For Each s As dataStructure In data
Next
Since the compiler complains that dataStructure is not defined. Is there a way to code around this?
i need to read binary file and in this file found the string and replace it with other one and save the file afterwords. I found many example to read binary, but to find and replace is for me mistery.
View 3 RepliesI need to write data to a file, preferably in binary format, but I am unaccustomed with the concept. Where's the easiest place to get the basics? I could come here with a specific need, but I'm at the point right now where I am more willing to work within the confines of keeping it simple.
Here's what I know:
1. how to open a new file
2. how to specify the record length
3. how to close the file
Some specific questions:
Does the record length have to be constant throughout the file?
Can I read the nth record without reading the whole file?
I've gone through about 16 hours and two packs of cigarettes trying to figure this out. First a little background. I was using 6.0 up until 2004 when I went to prison. I'm out now, and trying to relearn the trade, using VS 2005. I'm currently porting some 6.0 code from another project, SpyCast Webcam Studio, into VB 8.0. It's disheartening, to say the least. None of the old built-in subs/functions work anymore, so I have to scour the forums to relearn each and every function.The section I'm doing now takes a snapshot from the webcam (Video API --> PictureBox --> Save as Jpeg), then upens the file to upload it to the server via HTTP POST. I've been using this code in SpyCast for years with no trouble, but I spent many hours trying to piece together the right code to open the binary file to read its contents. I pieced together two methods I found around the forums, one using FileStream() though the code I found wasn't for binary files, even though it said it was, so that code doesn't really work. Method two uses Microsoft.VisualBasic.FileOpen() and works better.
Here's the kicker. By the time I run through the rest of the rigamarole of uploading the file, by the time I read it on the webserver, it's *slightly* corrupted. It's a valid Jpeg, no errors, but the picture looks like when I use to watch the Playboy Channel when I was a kid scrambled with weird colors and whatnot. [code] Each "chunk" is basically one "line" of the file. It looks like a single LineInput() return is the text between two carriage returns. Am I correct? I tested this with a flat text file, and it looks true. However, That one input line returns the text or data with the carriage returns *stripped*! ***?!? =( Fine, I have no problem adding my own vbCrLf to each LineInput(), if I were opening text. but this's binary. A character could be Chr(10) or Chr(13), both of which are removed from the original file contents.So I could very well need to use something other than LineInput(), but I haven't found any other examples on the web using this method.
how I could check if a certain file is in text or binary format?I'm using VB.Net 2008 Express.
View 2 RepliesProgram to convert binary pdf file to tiff file in VB.NET..?? We can use third party tools also..???
View 1 Replieshowever, I am stuck at BinaryReader.actually this is what i am trying to acheive through VB.NET.say for the following file type :
JPG file = FF D8 FF E0
BMP file = 42 4D BE 4E
PNG file = 89 50 4E 47
GIF file = 47 49 46 38
the above are the 4-byte headers in Hex(raw) I need to read these headers of any given file using OpenFileDialog using Button1_click event,on selection of any given file(*.* filters ON)it should use the BinaryReader and look for only 4-bytes starting from offset 0, and it should not go to EOF marker (-1).and have a variable to hold this 4-byte header value, to run this in a database table which will check the same header value in the table and would display the corresponding extension of the file. from the table.
I can do this using case, if then...etc.however, I have to do it using Database and also i need to check for testing purpose to use MsgBox() to display this variable which is holding the 4-byte header.however, the MsgBox doesnt allow anything other than String.
PS: I tried studying the methods like:
FileOpen/Seek/Peek/ReadBytes().
but still not sure how to get them work.
I need to save a datatable to a binary file , in binary format , in order to make the process fast because the datatable may contain up ten millions rows. So , XML is not favorable because it makes the file large sized , and the process will be slow.
I managed to save the datatable to a binary file , and it works fine , but the problem when I try to add new rows to the existing binary file (using a datatable with the same schema , but different rows data) , it copies the schema of the datatable to the binary file, making it very large.
[Code]...
I have a Binary file that has data represented in 1604 bytes. each set of data within these groups is composed of short (2 byte) numbers. I would like to creat a vb.net program that takes this binary file then converts it to numbers, and then places it within a new text file. How would I accomplish this?
View 9 RepliesI am reading a Binary file using BinaryReader in VB.NET.The structure of each row in the file is:
"Category" = 1 byte
"Code" = 1 byte
"Text" = 60 Bytes
Dim Category As Byte
Dim Code As Byte
[Code]...
i have a file any type of file and i want to display the binary of that file the (01) of that file can do it also i want to display the hexa which it better and faster if u just can put me on track
View 4 Repliesis anyone know how to get BMP image from binary file?
Offset Length Description
100 4 BMP_offset
268 4 Cover_size
296 4 Cover_offset
I've been using VB.NET for a few years now, but I never really got into binary files. How do you add onto binary files from the beginning? Here is some example code:
Dim writer As New IO.BinaryWriter(IO.File.Open("C:\Users\Dameon\Desktop\newbin.bin", IO.FileMode.CreateNew))
writer.Write("HELLO WORLD!")
[Code]....
How can I add onto the beginning of the file without overwriting what's already there? I'm trying to make my own file archive format. I have the compressing/decompressing down, but now I'm implementing adding/deleting a file after the archive already made.
I have existent binary files with this structure[code]...
View 13 RepliesI need make an application that gets binary code from a file, such as a .exe, (in 8-bit form) and display the charectors in a RichTextBox .BUT! The catch is I need it to do the process REALLY fast, like in a 5th 0.5 of a second. I have a method but it takes way to like, sometimes 5 seconds for 1 file, which isn't what I want This is the code I have:[CODE]......
View 9 RepliesI am not exactly sure how to say this, but what I want to do is to write a series of strings converted to their hex notation to a binary file. Here is what I have[code]....
View 8 RepliesHow do I change bytes [text stored in those bytes] in a binary file?
I have a little function that read bytes 335-343 [For Keyer] and bytes 344-352 [for verifier] and displays it. These bytes store who the keyerID and VerifierID of a data entry file are. From time to time the Verifier Resumes the file [to insert new records], and his/her name gets stored in the KeyerID bytes. So if the original keyer had lots of errors, the new verifier now becomes the owner of this file and the errors are attributed to him/her [not fair]. He/She gets penalized when there are lots of errors.
My question to you is, how do I change the content of those bytes and save it to the file, without damaging any part of the file? I want to save 'H345' in those bytes, [H345 is an example of a Keyer/Verifier ID]
note - as of now I am using 010 Editor [binary editor]to manually change those bytes. When I use this editor, I can see the text portions for those bytes.[code]...
Iam working in a project need converting a wave file to binary..converting a file of such format(wave) to binary text in asp.net? I need that cause i want to cut the original file to many files, and add additional parts of the same type to them and combine them together in a one file again..
View 2 RepliesRecently I experiment with the binary file type. I have this structure[code]...
It works. And now, in the load event of the form I want to know, how many records (structures) are stored in the file.
Another question: how can I search and seek in the file (structure to structure, not byte to byte)?
I am writing a windows desktop application in visual basic and I need it to connect to a SQL database, take a rows unique id, and using that number generate a file from the binary data that is stored in the SQL database and save it to a file directory. The part that is hanging me up is the creating the file from the binary SQL data.
View 2 RepliesI'm trying to save a binary file stored in a SQL database with a SaveDialog, the function RetrieveFile retrieves the specified file from the database as a Byte array, here's what I have so far:
Private Shared Function RetrieveFile(ByVal filename As String) As Byte()
Dim connection As New SqlConnection("Data Source=SERVERSQL2008;Initial Catalog=NorthPole;Integrated Security=True")
Dim command As New SqlCommand("SELECT pcfFile FROM Items WHERE pcfFileName=@Filename", connection)
command.Parameters.AddWithValue("@Filename", filename)
connection.Open()
[Code] .....
Files are saved as "SqlDbType.VarBinary" within the database.
I get: "Index was outside the bounds of the array." on:
Dim retrievedBytes As Long = reader.GetBytes(1, startIndex, buffer, 0, ChunkSize)
The MemoryStream appears to not be retrieving the data yet the SQL syntax is correct.
Join Date: Dec 10
Posts: 10
caba11 is an unknown quantity at this point (<10)
How to save binary file to database. Ineed to save files into database. I cant find why it is not working...
This is my code:
Public Sub importfiles(ByVal sFileName As String)
Dim cnSQL As SqlConnection
Dim cmSQL As SqlCommand
Dim strSQL
'Validate form values
[Code] .....
Without try it says "cmSQL.ExecuteNonQuery()"-"Failed to convert parameter value from a DataGridViewTextBoxColumn to a Int32."