Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dump form results to csv using asp

Posted on 2009-04-01
3
Medium Priority
?
541 Views
Last Modified: 2012-08-13
Hi,

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.
Bonnie
0
Comment
Question by:Bonnie_K
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 1040 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) & ","
Next
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
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_20703102.html?sfQueryTermInfo=1+10+asp+csv+writeSnippet below is from the page

...
 Dim strTmp, F
      set FSO = Server.CreateObject("scripting.FileSystemObject")
      set csv = fso.CreateTextFile("C:\Inetpub\wwwroot\file.csv", true)
...
csv.WriteLine(fields)

Open in new window

0
 
LVL 22

Assisted Solution

by:neeraj523
neeraj523 earned 960 total points
ID: 24046548
Hello

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
		fsys.createTextFile(fileName)
	End If
	For Each i In Request.Form
        ValStr = ValStr & Request.Form(i) & ","
	Next
	Set fo = fsys.openTextFile(fileName, 8)
	fo.writeline ValStr
	fo.Close
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">
</form>

Open in new window

0
 

Author Comment

by:Bonnie_K
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];
                }
                else 
                {
                    answers = answers + "," + Request.Form[item];
                }
                
            }
        }
        gw.WriteLine(answers);
        gw.Close();
    }
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

610 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