473,419 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

NameValueCollection Serialization Deserialization

We are trying to serialize the Request.ServerVariables collection
(NameValueCollection) to an XML formatted string, to insert into a database.
The problem we are running into is that most of the example that we find
discuss writing to a file. Does anyone have a simple function to do this?

We would also like to deserialize the string from the database back into a
NameValueCollection.

--
Mike Logan
Nov 19 '05 #1
3 10609
It's sad, but you can't use the XmlSerializer for this. the only easy/good
alternative I know of is to use the SoapFormatter:

NameValueCollection values = new NameValueCollection();
values.Add("one", "two");
values.Add("a", "b");

SoapFormatter ser = new SoapFormatter();
MemoryStream ms = new MemoryStream();
ser.Serialize(ms, values);
byte[] b = ms.GetBuffer();
string s = Encoding.Default.GetString(b);
ms.Close();

you'll need to add a reference to
System.Runtime.Serialization.Formatters.Soap.dll

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mike Logan" <Mi*******@community.nospam> wrote in message
news:24**********************************@microsof t.com...
We are trying to serialize the Request.ServerVariables collection
(NameValueCollection) to an XML formatted string, to insert into a database. The problem we are running into is that most of the example that we find
discuss writing to a file. Does anyone have a simple function to do this?

We would also like to deserialize the string from the database back into a
NameValueCollection.

--
Mike Logan

Nov 19 '05 #2
Thanks Karl! This will help tremendously. Can this string be deserialized
back into a NameValueCollection as well?

"Karl Seguin" wrote:
It's sad, but you can't use the XmlSerializer for this. the only easy/good
alternative I know of is to use the SoapFormatter:

NameValueCollection values = new NameValueCollection();
values.Add("one", "two");
values.Add("a", "b");

SoapFormatter ser = new SoapFormatter();
MemoryStream ms = new MemoryStream();
ser.Serialize(ms, values);
byte[] b = ms.GetBuffer();
string s = Encoding.Default.GetString(b);
ms.Close();

you'll need to add a reference to
System.Runtime.Serialization.Formatters.Soap.dll

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mike Logan" <Mi*******@community.nospam> wrote in message
news:24**********************************@microsof t.com...
We are trying to serialize the Request.ServerVariables collection
(NameValueCollection) to an XML formatted string, to insert into a

database.
The problem we are running into is that most of the example that we find
discuss writing to a file. Does anyone have a simple function to do this?

We would also like to deserialize the string from the database back into a
NameValueCollection.

--
Mike Logan


Nov 19 '05 #3
Yes, if you pull up the documentation for SoapFormatter you'll see....but,
as you probably could have guessed, there's a Deserialize function ;)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mike Logan" <Mi*******@community.nospam> wrote in message
news:9D**********************************@microsof t.com...
Thanks Karl! This will help tremendously. Can this string be deserialized
back into a NameValueCollection as well?

"Karl Seguin" wrote:
It's sad, but you can't use the XmlSerializer for this. the only easy/good alternative I know of is to use the SoapFormatter:

NameValueCollection values = new NameValueCollection();
values.Add("one", "two");
values.Add("a", "b");

SoapFormatter ser = new SoapFormatter();
MemoryStream ms = new MemoryStream();
ser.Serialize(ms, values);
byte[] b = ms.GetBuffer();
string s = Encoding.Default.GetString(b);
ms.Close();

you'll need to add a reference to
System.Runtime.Serialization.Formatters.Soap.dll

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mike Logan" <Mi*******@community.nospam> wrote in message
news:24**********************************@microsof t.com...
We are trying to serialize the Request.ServerVariables collection
(NameValueCollection) to an XML formatted string, to insert into a

database.
The problem we are running into is that most of the example that we find discuss writing to a file. Does anyone have a simple function to do this?
We would also like to deserialize the string from the database back into a NameValueCollection.

--
Mike Logan


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
4
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
1
by: Maheal | last post by:
I have been trying to Serialize an object that is the child of another object which is also serializable. Here is the simplified scenario (assume missing code is correct): class One :...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
0
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk...
1
by: Rucha | last post by:
We are using ACAServices in our project, and are passing entity classes as parameters to the ACAServiceMethod. We are using a private variable entityState to indicate whether the entity is...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
3
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.