Skip to content

Instantly share code, notes, and snippets.

@UdaraAlwis
Created December 17, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UdaraAlwis/8d547f68ae3f629d40b2184f51acd43e to your computer and use it in GitHub Desktop.
Save UdaraAlwis/8d547f68ae3f629d40b2184f51acd43e to your computer and use it in GitHub Desktop.
Submit form data to your Google Form from dotnet C# with ease! ;) #GoogleFormsToolkitLibrary
/// <summary>
/// Submit Form data to your Google Form
/// </summary>
/// <param name="yourGoogleFormsUrl">
/// Link to your Google Form page
/// </param>
/// <param name="formData">
/// Form data dictionary to submit
/// TKey: FieldSubmissionId - TValue: Value
/// </param>
/// <returns></returns>
public async Task<bool> SubmitToGoogleFormAsync(string yourGoogleFormsUrl, Dictionary<string, string> formData)
{
// Init HttpClient to send the request
HttpClient client = new HttpClient();
// Encode object to application/x-www-form-urlencoded MIME type
var content = new FormUrlEncodedContent(formData);
// Post the request (replace with your Google Form link)
var response = await client.PostAsync(
yourGoogleFormsUrl,
content);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment