Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

How to Submit Google Docs Form by using C#

4.56/5 (5 votes)
21 Sep 2012CPOL 58.9K  
Submitting (HTML) specifically Google Docs Form in C#

Step 1

(UPDATED!) SEP 2012

First create your form in Google doc.

Step 2

Open the form and check the source to find this line, and copy the Action parameter value:

HTML
<form action=https://docs.google.com/formResponse?formkey=XXXXXXX&amp;ifq 
method="POST" id="ss-form"> 

Step 3

Use this method to submit a new entry in your C# code (this example is for a form with two textboxes):

C#
void SubmitGoogleDoc(){
            //Use WebClient Class to submit a new entry
            WebClient wc = new WebClient();
            var keyval = new NameValueCollection();
            keyval.Add("entry.0.single", "XXXX");
            keyval.Add("entry.1.single", "XXXX");
            
            keyval.Add("submit", "Submit");
            
            //Create an event for Submit Complete
            wc.UploadValuesCompleted += 
            new UploadValuesCompletedEventHandler(wc_UploadValuesCompleted);
            //Create Additional Headers  
            
            wc.Headers.Add("Origin", "https://docs.google.com");
            wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) 
            AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10");
            
            //Finally Submit the Form:
            wc.UploadValuesAsync(new Uri
            ("https://docs.google.com/formResponse?formkey=XXXXX&ifq"), 
            "POST", keyval, Guid.NewGuid().ToString());
            
        } 
C#
void wc_UploadValuesCompleted(object sender, UploadValuesCompletedEventArgs e)
{
    //Submit Complete
}

Thanks.

Hope this small tip will make you happy. Smile | <img src=

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)