Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > NameValueCollection Serialization Deserialization

Reply
Thread Tools

NameValueCollection Serialization Deserialization

 
 
=?Utf-8?B?TWlrZSBMb2dhbg==?=
Guest
Posts: n/a
 
      12-22-2004
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
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      12-22-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBMb2dhbg==?=
Guest
Posts: n/a
 
      12-22-2004
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      12-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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

> >
> >
> >



 
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
Serialization/Deserialization Error andrewzzz Java 0 12-16-2008 03:08 PM
Axis1 Serialization/Deserialization Issue andrewzzz Java 0 12-12-2008 05:41 PM
Design Patterns for C++ Object Serialization/Deserialization? Nimmi Srivastav C++ 12 05-29-2004 11:30 AM
Serialization/Deserialization or XML as DB umbertoeklat@yahoo.com ASP .Net 3 05-14-2004 03:47 PM



Advertisments