How can I duplicate the form data?

H

Harry Haller

I want to duplicate the form data, edit it to remove some items (such
as __EVENTTARGET, __EVENTVALIDATION, etc) and save it to a log.

How can I make a duplicate (editable) copy of the Form Collection?

The Form Collection is of type NameValueCollection is, underneath the
covers, an object of type HttpValueCollection.

The problem I have is that my copies have only one key item for a list
(such as a radio button list) whereas the Form has one key per item in
the collection (duplicate keys).

Apart from doing something like:

string aCopy = myForm.ToString();

and then rebuilding the NameValueCollection how can I make an editable
duplicate with duplicate keys for lists?

myForm is passed into a method so:

public void TheHeader(NameValueCollection myForm)
{
...

the calling code is:

SomeClass.TheHeader(Request.Form);

When this happens the resulting myForm is read only.

The code within TheHeader could be:

NameValueCollection nvc = new NameValueCollection();
foreach (string key in myForm)
nvc.Add(key, myForm[key]);

or below which duplicates the above (using the 1st contructor of the
Add method rather than 2nd):

NameValueCollection nvc = new NameValueCollection();
nvc.Add(Request.Form)

No matter how the Form is copied the copy isn't the same because the
original Form has a separate key for each item in a collection (such
as a radio button list). The copy (nvc) will contain only one key
followed by a comma separated value list.

If I serialise it to a string and then use split to put it into an
array how can I be sure that the viewstate and other asp.net fields
won't this up by using the special characters & = , used to delimit
the keys and data?
 
P

Patrice

Just get them all and ignore what you want when dumping to the log file ?

It could be just done in global.asax using the request.form collection (if I
understand what you are trying to do) so that it is easily
changed/removed/added as needed.

(My understanding is that you want just to keep track of posted values in a
server side log.)
 
M

mark4asp

The following doesn't work either:

NameValueCollection nvc = new NameValueCollection(myForm);

once again the resulting collection has only one key for a radio
button list values rather than a key per entry (as in the original
form).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top