sdrose65 / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

DocListExporter Export function crashes #509

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1. Download version 1.8.0 of SDK
2. Compile, run DocListExporter, login
3. Select a document and click Export

What is the expected output? What do you see instead?
Most of the time, application crashed with the following message
************** Exception Text **************
Google.GData.Client.GDataRequestException: Execution of request failed: 
https://docs.google.com/feeds/download/documents/Export?docID=document:AAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAA&exportFormat=ods ---> System.Net.WebException: The 
remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
...
(I replaced the docID value with dummy values 
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")

As per 
http://code.google.com/apis/documents/docs/3.0/reference.html#ExportParameters, 
the docID query string value is incorrect

Instead of 
docID=document:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

It should be 
docID=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

What is the Fix?

Modify docRequest.cs file in SDK.
Look for public Stream Download(Document document, Document.DownloadType type, 
string baseDomain, int sheetNumber)  (page 639)
Replace as follows

== ORIGINAL ==
queryUri = baseDomain + "feeds/download/spreadsheets/Export?key=" + 
document.ResourceId + "&exportFormat=";

== NEW ==
if (document.ResourceId.Contains(":"))
queryUri = baseDomain + "feeds/download/spreadsheets/Export?key=" + 
document.ResourceId.Substring(document.ResourceId.IndexOf(":") + 1) + 
"&exportFormat=";

== ORIGINAL ==
queryUri = baseDomain + "feeds/download/presentations/Export?docID=" + 
document.ResourceId + "&exportFormat=";
== NEW ==
if (document.ResourceId.Contains(":"))
queryUri = baseDomain + "feeds/download/presentations/Export?docID=" + 
document.ResourceId.Substring(document.ResourceId.IndexOf(":") + 1) + 
"&exportFormat=";

== ORIGINAL ==
queryUri = baseDomain + "feeds/download/documents/Export?docID=" + 
document.ResourceId + "&exportFormat=" + type.ToString();
== NEW ==
if (document.ResourceId.Contains(":"))
queryUri = baseDomain + "feeds/download/documents/Export?docID=" + 
document.ResourceId.Substring(document.ResourceId.IndexOf(":") + 1) + 
"&exportFormat=" + type.ToString();

Compile Google.GData.Documents.DLL (need to set AssemblyVersion to 1.8.0.0)
Replace the DLL in %Program Files%\Google\Google Data API SDK\Redist
Recompile DocListExporter

Export now works for all file types.

(Modified docrequest.cs file attached)

Original issue reported on code.google.com by Mike.Lim...@gmail.com on 26 May 2011 at 1:48

Attachments:

GoogleCodeExporter commented 9 years ago
Just to be safe, I updated the code to this format

queryUri = baseDomain 
+ "feeds/download/documents/Export?docID=" 
+ (document.ResourceId.Contains(":") ? 
document.ResourceId.Substring(document.ResourceId.IndexOf(":") + 1) : 
document.ResourceId) 
+ "&exportFormat=" + type.ToString(); 

Original comment by Mike.Lim...@gmail.com on 26 May 2011 at 2:25

Attachments:

GoogleCodeExporter commented 9 years ago
Only a suggestion/workaround: there is another version of the Download method.
Use:  Stream Download(Document,string)  It works fine.

Original comment by fht...@gmail.com on 26 May 2011 at 5:59

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion.
I prefer Download(Document document, Document.DownloadType type) over 
Download(Document document, string exportFormat), as we can use intellisense 
for  download type.

Also prefer a working DecListExporter application that newbies like me can 
study and learn from.

Original comment by Mike.Lim...@gmail.com on 26 May 2011 at 2:09

GoogleCodeExporter commented 9 years ago
Mike,

Thanks for the patch, I committed it in rev. 1103.

Original comment by ccherub...@google.com on 9 Jun 2011 at 11:13

GoogleCodeExporter commented 9 years ago
Issue 411 has been merged into this issue.

Original comment by ccherub...@google.com on 10 Jun 2011 at 9:34

GoogleCodeExporter commented 9 years ago
ccherub,

You merged issue 411 into this one, but don't know if this issue fully 
addresses 411.  

One of the main things that we thought should be changed is the way the export 
url is come to.  In the current code, it is still being constructed out of the 
resource ID.  This way is not preferred, because the Document object is passed 
into the Download Function as a parameter.  The Document object already has the 
export url in it:  Document.DocumentEntry.Content.Src .  We shouldn't have to 
construct it from scratch.

Original comment by ed...@edwinlandy.com on 10 Jun 2011 at 10:21

GoogleCodeExporter commented 9 years ago
Edwin, you're right, this partially addresses issue 411.

Would you like to propose a patch to correct the way the export url is 
constructed?

Original comment by ccherub...@google.com on 10 Jun 2011 at 10:29