Groups is going to make this an absolute mess, but here is my test script:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Google.GData.Documents; using Google.GData.Client; using Google.GData.Extensions; using System.IO; using System.Collections; using Google.Documents; namespace ConsoleApplication1 { class Program { static public DocumentsService service = null; public static Hashtable GDocumentsAllowedTypes; /// <summary> /// Static constructor used to initialize GDocumentsAllowedTypes. /// </summary> static Program() { GDocumentsAllowedTypes = new Hashtable(); GDocumentsAllowedTypes.Add("CSV", "text/csv"); GDocumentsAllowedTypes.Add("TAB", "text/tab-separated- values"); GDocumentsAllowedTypes.Add("TSV", "text/tab-separated- values"); GDocumentsAllowedTypes.Add("TXT", "text/plain"); GDocumentsAllowedTypes.Add("HTML", "text/html"); GDocumentsAllowedTypes.Add("HTM", "text/html"); GDocumentsAllowedTypes.Add("DOC", "application/msword"); GDocumentsAllowedTypes.Add("DOCX", "application/msword"); GDocumentsAllowedTypes.Add("ODS", "application/x- vnd.oasis.opendocument.spreadsheet"); GDocumentsAllowedTypes.Add("ODT", "application/ vnd.oasis.opendocument.text"); GDocumentsAllowedTypes.Add("RTF", "application/rtf"); GDocumentsAllowedTypes.Add("SXW", "application/ vnd.sun.xml.writer"); GDocumentsAllowedTypes.Add("XLSX", "application/vnd.ms- excel"); GDocumentsAllowedTypes.Add("XLS", "application/vnd.ms-excel"); GDocumentsAllowedTypes.Add("PPT", "application/vnd.ms- powerpoint"); GDocumentsAllowedTypes.Add("PPS", "application/vnd.ms- powerpoint"); GDocumentsAllowedTypes.Add("PDF", "application/pdf"); } static void Main(string[] args) { service = new DocumentsService("companyName-AppName- versionNum"); service.setUserCredentials("u...@gmail.com", "password"); service.QueryAuthenticationToken(); // Authenticate the user immediately DocumentsFeed doclistFeed = service.Query(new DocumentsListQuery ()); DocumentEntry entry = (DocumentEntry)doclistFeed.Entries[0]; Console.WriteLine("Updating " + entry.Title.Text); DocumentEntry updatedEntry = ReplaceDocContents(entry, "C:\ \replace.doc"); Console.WriteLine(entry.Title.Text + " Updated!"); Console.WriteLine("view at " + entry.AlternateUri.ToString()); Console.Read(); // hang } static public DocumentEntry ReplaceDocContents(DocumentEntry entryToUpdate, string replacementFileName) { DocumentEntry entry = null; FileInfo fileInfo = new FileInfo(replacementFileName); FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); try { //convert the extension to caps and strip the "." off the front string ext = fileInfo.Extension.ToUpper().Substring(1); String contentType = (String)GDocumentsAllowedTypes[ext]; if (contentType == null) { throw new ArgumentException("File extension '" + ext + "' is not recognized as valid."); } GDataRequestFactory factory = (GDataRequestFactory) service.RequestFactory; factory.CustomHeaders.Add("If-Match: " + entryToUpdate.Etag); service.RequestFactory = factory; entry = service.Update(new Uri(entryToUpdate.MediaUri.ToString ()), stream, contentType, entryToUpdate.Title.Text) as DocumentEntry; } finally { stream.Close(); } return entry; } } } Eric On Jun 16, 11:41 am, harry mendell <harry.mend...@gmail.com> wrote: > OK, I will do that, but in my interest for self-preservation I would > like to be able to get something working today. I almost considered > hiring a temp to hit the update button onthe docs update button on the > docs.google.com page every minute (LOL), I also thought of using > Amazon's mechanical turk and offer .05 an upload :) > > Since we have gone so far with this to you have anything else I can > try before my surrender? > On Jun 16, 2009, at 1:59 PM, Eric Bidelman wrote: > > > > > See my earlier reply. Java and Python are the most complete w.r.t. > > examples > > and code snippets in the docs: > >http://code.google.com/apis/documents/docs/2.0/developers_guide_java.... > >http://code.google.com/apis/documents/docs/1.0/developers_guide_pytho... > > > E > > > On Tue, Jun 16, 2009 at 8:00 AM, harry mendell <harry.mend...@gmail.com > > > wrote: > > Stuck again! Do any of the new apis support all of the high level > > client code, If so I'm hitting the ejector seat button. I don't care > > if I have to learn a new language from scratch be it "ruby on rails > > or whatever", the whole point of this exercise is to make developing > > new apps a " LEGO kit". Otherwise I am going to have to really study > > these low level protocols. It reminds me of my old assembler days. > > The more things change the more they remain the same. At least I can > > see from the other forum posts that I am not alone in my > > frustration. Step back for a second. Almost all of the forum > > questions involve what is essentially reading and writing data. I > > thought that was solved in the 1960s :) > > > I have a suggestion. Take all of the classes/methods that allow > > public and published data and produce a private and behind the > > firewall version that does exactly the same thing. Boom! Problems > > solved at once and I'll have a chance using Google internally. - Harry > > > In the mean time could you please sherpa me to mid-base? > > On Jun 15, 2009, at 7:50 PM, Eric Bidelman wrote: > > >> That 3rd parameter to update is a mimetype, not an file extension. > >> That's the GDocumntsAllowedType hashmap takes care of :) > > >> try: text/csv > > >> Eric > > >> On Mon, Jun 15, 2009 at 4:35 PM, harry mendell <harry.mend...@gmail.com > >> > wrote: > >> Google.GData.Client.GDataRequestException was unhandled > >> Message="Execution of request > >> failed:http://docs.google.com/feeds/media/private/full/spreadsheet:rqfFdRlpa... > >> " > >> Source="Google.GData.Client" > >> ResponseString="Malformed Content-Type" > >> StackTrace: > >> at Google.GData.Client.GDataRequest.Execute() > >> at Google.GData.Client.GDataGAuthRequest.Execute(Int32 > >> retryCounter) > >> at Google.GData.Client.GDataGAuthRequest.Execute() > >> at Google.GData.Client.Service.StreamSend(Uri targetUri, > >> Stream inputStream, GDataRequestType type, String contentType, > >> String slugHeader, String etag, AsyncSendData data) > >> at Google.GData.Client.Service.StreamSend(Uri targetUri, > >> Stream inputStream, GDataRequestType type, String contentType, > >> String slugHeader) > >> at Google.GData.Client.Service.Update(Uri uriTarget, Stream > >> input, String contentType, String slugHeader) > >> at myfirstcsharp.Program.Main(String[] args) in C:\Documents > >> and Settings\harry\My Documents\Visual Studio 2008\Projects > >> \updatesheet\myfirstcsharp\Program.cs:line 54 > >> at System.AppDomain._nExecuteAssembly(Assembly assembly, > >> String[] args) > >> at System.AppDomain.nExecuteAssembly(Assembly assembly, > >> String[] args) > >> at System.Runtime.Hosting.ManifestRunner.Run(Boolean > >> checkAptModel) > >> at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() > >> at > >> System > >> .Runtime > >> .Hosting.ApplicationActivator.CreateInstance(ActivationContext > >> activationContext, String[] activationCustomData) > >> at > >> System > >> .Runtime > >> .Hosting.ApplicationActivator.CreateInstance(ActivationContext > >> activationContext) > >> at System.Activator.CreateInstance(ActivationContext > >> activationContext) > >> at > >> Microsoft > >> .VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() > >> at System.Threading.ThreadHelper.ThreadStart_Context(Object > >> state) > >> at System.Threading.ExecutionContext.Run(ExecutionContext > >> executionContext, ContextCallback callback, Object state) > >> at System.Threading.ThreadHelper.ThreadStart() > >> InnerException: System.Net.WebException > >> Message="The remote server returned an error: (400) Bad > >> Request." > >> Source="System" > >> StackTrace: > >> at System.Net.HttpWebRequest.GetResponse() > >> at Google.GData.Client.GDataRequest.Execute() > >> InnerException: > > >> On Jun 15, 2009, at 6:49 PM, Eric Bidelman wrote: > > >>> Sorry. The definition of GDocumntsAllowedType is in the lib's > >>> source: > >>>http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/... > > >>> What is the exception/response from the server? > > >>> Eric > > >>> On Mon, Jun 15, 2009 at 3:37 PM, harry mendell <harry.mend...@gmail.com > >>> > wrote: > > >>> Dear Eric, > >>> I tried adapting your code and wrote a test which I copied > >>> below. It fails at > >>> DocumentEntry entry = service.Update(new > >>> Uri(lastUploadEntry.MediaUri.ToString()), stream, "CSV", > >>> lastUploadEntry.Title.Text) as DocumentEntry; > >>> which is almost at the bottom. I think I'm having a some code of > >>> compatibility issue between the ACL and token auth, but this end > >>> of the pool is pretty deep. > >>> Would you mind taking a look? > >>> Thanks, > >>> Harry > > >>> using System; > >>> using System.IO; > >>> using System.Collections; > >>> using System.Net; > >>> using System.Collections.Generic; > >>> using Google.Spreadsheets; > >>> using System.Linq; > >>> using System.Text; > >>> using Google.GData.Documents; > >>> using Google.GData.Client; > >>> using Google.GData.Extensions; > > >>> namespace myfirstcsharp > >>> { > > >>> class Program > >>> { > >>> static void Main(string[] args) > >>> { > >>> DocumentsService service = new DocumentsService("HBM- > >>> DocListUploader-1"); > > >>> ((GDataRequestFactory)service.RequestFactory).KeepAlive = false; > >>> service.setUserCredentials("qvtuat", "qvtqvtqvt"); > >>> //force the service to authenticate > >>> DocumentsListQuery query = new DocumentsListQuery(); > >>> query.NumberToRetrieve = 1; > >>> service.Query(query); > > >>> // For testing only. Creates document called radar.csv > >>> DocumentEntry lastUploadEntry = > >>> service.UploadDocument("c:/radar.csv", "radar.csv"); > >>> // For testing only. Now lets see if we can update it > >>> FileInfo fileInfo = new FileInfo("c:/radar.csv"); > >>> FileStream stream = fileInfo.Open(FileMode.Open, > >>> FileAccess.Read, FileShare.ReadWrite); > > >>> try > >>> { > >>> /* It didn't recogize GDocumntsAllowedType so I > >>> commented the check since I know its good type > >>> // convert the extension to caps and strip the "." > >>> off the front > >>> string ext = > >>> fileInfo.Extension.ToUpper().Substring(1); > >>> String contentType = > >>> (String)GDocumentsAllowedTypes[ext]; > > >>> if (contentType == null) > >>> { > >>> throw new ArgumentException("File extension '" > >>> + ext + "' is not recognized as valid."); > >>> } > >>> // Make sure we don't overwrite someone else's > >>> changes. Use entry's ETag > >>> */ > >>> GDataRequestFactory factory = > >>> (GDataRequestFactory)service.RequestFactory; > >>> factory.CustomHeaders.Add("If-Match: " + > >>> lastUploadEntry.Etag); > >>> service.RequestFactory = factory; > >>> DocumentEntry entry = service.Update(new > >>> Uri(lastUploadEntry.MediaUri.ToString()), stream, "CSV", > >>> lastUploadEntry.Title.Text) as DocumentEntry; > >>> } > >>> finally > >>> { > >>> stream.Close(); > >>> } > >>> } > >>> } > >>> } > > >>> On Jun 11, 2009, at 5:16 PM, Eric (Google) wrote: > > >>>> This worked for me: > > >>>> DocumentsService service = new DocumentsService("yourCompany- > >>>> AppName- > >>>> v1"); > >>>> // TODO: Fetch DocumentEntry > >>>> ReplaceDocContents(entryToUpdate, "C:\somewhere\test.doc"); > >>>> ... > > >>>> static public DocumentEntry ReplaceDocContents(DocumentEntry > >>>> entryToUpdate, string replacementFileName) > >>>> { > >>>> DocumentEntry entry = null; > > >>>> FileInfo fileInfo = new FileInfo(replacementFileName); > >>>> FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, > >>>> FileShare.ReadWrite); > > >>>> try > >>>> { > >>>> // convert the extension to caps and strip the "." off the front > >>>> string ext = fileInfo.Extension.ToUpper().Substring(1); > > >>>> String contentType = (String)GDocumentsAllowedTypes[ext]; > > >>>> if (contentType == null) > >>>> { > >>>> throw new ArgumentException("File extension '" + ext + > >>>> "' is not recognized as > >>>> valid."); > >>>> } > > >>>> // Make sure we don't overwrite someone else's changes. Use > >>>> entry's ETag > >>>> GDataRequestFactory factory = (GDataRequestFactory) > >>>> service.RequestFactory; > >>>> factory.CustomHeaders.Add("If-Match: " + entryToUpdate.Etag); > >>>> service.RequestFactory = factory; > > >>>> entry =... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Docs Data APIs" group. To post to this group, send email to Google-Docs-Data-APIs@googlegroups.com To unsubscribe from this group, send email to google-docs-data-apis+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Docs-Data-APIs?hl=en -~----------~----~----~----~------~----~------~--~---