title: How to download Google SpreadSheets using C#?
body: <p>I'm able to login to google with my application with the following code which I found from web. It is returning an Authorization Code as response. Google help says that this auth code should be used to send future POST/GET requests. </p>
  
  <p>I need to download a spreadsheet in Excel format from 
  <a href="http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=DOCUMENT_ID&amp;fmcmd=4" rel="noreferrer">http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=DOCUMENT_ID&amp;fmcmd=4</a>  which I can normally do from my browser when I'm logged in to google.</p>
  
  <p>How can I send a request for the above file with the Authorization code in C#? 
  I have seen a thread in SO which used Google Data API. I don't want to make use of it. </p>
  
  <p>Below is the code sample for logging in. It works fine.    </p>
  
  <pre><code>        string str = "/accounts/ClientLogin HTTP/1.0 Content-type: application/x-www-form-urlencoded accountType=GOOGLE&amp;Email=myname@gmail.com&amp;Passwd=password&amp;service=cl&amp;source=Gulp-CalGulp-1.05";
  
          string uri = "https://www.google.com/accounts/ClientLogin";
  
          HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); 
          request.KeepAlive = false;
          request.ProtocolVersion = HttpVersion.Version10;
          request.Method = "POST";
  
          byte[] postBytes = Encoding.ASCII.GetBytes(str);
  
          request.ContentType = "application/x-www-form-urlencoded";
          request.ContentLength = postBytes.Length;
          Stream requestStream = request.GetRequestStream();
  
  
          requestStream.Write(postBytes, 0, postBytes.Length);
          requestStream.Close();
  
  
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          StringBuilder sb = new StringBuilder();
  
          string webresponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
          int AuthIndex = webresponse.IndexOf("Auth=");
  
          sb.Append(webresponse);
          sb.Append("\n");
          sb.Append(response.StatusCode);
  
          richTextBox1.Text = sb.ToString();
          string authCode = webresponse.Substring(AuthIndex + 5, webresponse.Length - (AuthIndex + 5));
  </code></pre>
  
  <p>EDITED:
  This is what I get as response when I did according to what miffTheFox has replied:</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;Redirecting&lt;/title&gt;
  &lt;meta http-equiv="refresh" content="0; url=&amp;#39;http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=p_zC6U3bOsLTuXeUdmQI1RA&amp;amp;fmcmd=4&amp;amp;pli=1&amp;amp;auth=DQAAAIoAAAAfbQUnX8EaZzQcBSIRJSeU4xtFF6ITt9069JLJyJsoqFGMzSE8HrvArHmGPoA-Wf2CbhnDQv_bGKXye2_qyL6EAhTEdOs6Alz-VMeYFsqdGlYjxospBokgCO1958kSVuVFRe9UuKkfV2f_6ZX8SROMkMNdMz3MW8Wh3UNmflIX4E92CpnMleSjCRVpH9x5gSQ&amp;amp;gausr=username%40gmail.com&amp;#39;"&gt;&lt;/head&gt;
  &lt;body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#551a8b" alink="#ff0000"&gt;&lt;script type="text/javascript" language="javascript"&gt;
      location.replace("http://spreadsheets.google.com/feeds/download/spreadsheets/Export?key\x3dp_zC6U3bOsLTuXeUdmQI1RA\x26fmcmd\x3d4\x26pli\x3d1\x26auth\x3dDQAAAIoAAAAfbQUnX8EaZzQcBSIRJSeU4xtFF6ITt9069JLJyJsoqFGMzSE8HrvArHmGPoA-Wf2CbhnDQv_bGKXye2_qyL6EAhTEdOs6Alz-VMeYFsqdGlYjxospBokgCO1958kSVuVFRe9UuKkfV2f_6ZX8SROMkMNdMz3MW8Wh3UNmflIX4E92CpnMleSjCRVpH9x5gSQ\x26gausr\x3dusername%40gmail.com")
    &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>If I save the stream as HTML and open it in browser it is prompting for downloading the Excel file which I need to download directly.</p>