NameValueCollection Serialization Deserialization

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZSBMb2dhbg==?=, Dec 22, 2004.

  1. 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
     
    =?Utf-8?B?TWlrZSBMb2dhbg==?=, Dec 22, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?TWlrZSBMb2dhbg==?=

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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
     
    Karl Seguin, Dec 22, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
     
    =?Utf-8?B?TWlrZSBMb2dhbg==?=, Dec 22, 2004
    #3
  4. =?Utf-8?B?TWlrZSBMb2dhbg==?=

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > > news:...
    > > > 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

    > >
    > >
    > >
     
    Karl Seguin, Dec 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    647
    Sahil Malik
    May 14, 2004
  2. Nimmi Srivastav
    Replies:
    12
    Views:
    13,457
    EventHelix.com
    May 29, 2004
  3. andrewzzz
    Replies:
    0
    Views:
    381
    andrewzzz
    Dec 12, 2008
  4. andrewzzz
    Replies:
    0
    Views:
    328
    andrewzzz
    Dec 16, 2008
  5. Robert Millman

    Serialization / Deserialization across WebService Calls

    Robert Millman, Feb 5, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    100
Loading...

Share This Page