Dump form results to csv using asp

Posted on 2009-04-01
Last Modified: 2012-08-13

I have a form for users to fill out.  Is there a way the request the data from all of the fields submitted without having to reference each input?  I want everything submitted to be dumped to a text string that I can manipulate.  I have a user that wants to create questionnaires and not have to have me program the results gathering every time the questionnaire changes.  That is why I am asking.  I want to be able to get all of the data then I can program the data to go to a format that he can read.

Do I just submit the form to a file?  

Thanks for any ideas.
Question by:Bonnie_K
LVL 23

Accepted Solution

apresto earned 260 total points
ID: 24041791
Well, to get all of the field submitted, you can just loop the Request.Form collection:
Dim fields
For Each x In Request.Form
        fields = field & Request.Form(x) & ","
This will append all of your form values to a tring like this:
Val1, val2, val3
If you want to then add these to a CSV, see here for an example on how to write a CSV file from ASP below is from the page


 Dim strTmp, F

      set FSO = Server.CreateObject("scripting.FileSystemObject")

      set csv = fso.CreateTextFile("C:\Inetpub\wwwroot\file.csv", true)



Open in new window

LVL 22

Assisted Solution

neeraj523 earned 240 total points
ID: 24046548

It is quiet simple..

here is a fully functional example..


If Request("SubmitBTN") <> "" Then

	Set fsys = Server.CreateObject("SCRIPTING.FileSystemObject")

	fileName = Server.MapPath("/") & "/SubmitedData.csv"

	If NOT fsys.FileExists(fileName) Then


	End If

	For Each i In Request.Form

        ValStr = ValStr & Request.Form(i) & ","


	Set fo = fsys.openTextFile(fileName, 8)

	fo.writeline ValStr


End if


<form action="" METHOD="POST">

	Name: <input type="text" name="t1"><br />

	Age: <input type="text" name="t2"><br />

	City: <input type="text" name="t3"><br />

	Country: <input type="text" name="t4"><br />

	<input type="submit" name="submitBTN" value="Submit">


Open in new window


Author Comment

ID: 24048036
I forgot to mention that I use C#.  However, your answers regarding how to collect all of the request.form objects were exactly what I needed.  Thanks a lot.
using System.IO;

public partial class Questionnaires_test2 : System.Web.UI.Page


    protected void Button1_Click(object sender, EventArgs e)


        String outputFile = Server.MapPath("./results.csv");

        StreamWriter gw = new StreamWriter(outputFile, false);

        string answers = "";



        foreach (string item in Request.Form)



            if (Request.Form[item] != null)


                if (answers.Length == 0)


                    answers = Request.Form[item];




                    answers = answers + "," + Request.Form[item];









Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now