Hi,
I am currently testing the google API. It seems promising, but I am stuck at a "simple" problem. I want to update an existing document with a local copy.
My idea was, download all google documents to a folder, using the doc-download. That works. At the next run, I check the dates, if a remote document is newer, grab it again. If the local document is newer, upload it, and replace the current online version.
I can't find a function to replace a document. There is a Upload(filename, doctitle) but this creates a new document. Does anybody know if this is possible and can point me in the correction direction. Do I have to dissect the atom feed (is the document content somewhere inside it..). The "download / change in word / upload" looked so nice :-)
Chris
And for anyone who is interested, its pretty simple and nice to use the API. Here is a short WPF example (without credentials, of course)
var settings = new RequestSettings("GoogleDocumentsSample", _credentials);
AllDocuments = new ObservableCollection<Document>();
settings.AutoPaging = true;
settings.PageSize = 10;
service = new DocumentsService("DocListUploader");
((GDataRequestFactory)service.RequestFactory).KeepAlive = false;
service.setUserCredentials(username, password);
//force the service to authenticate
var query = new DocumentsListQuery {NumberToRetrieve = 1};
service.Query(query);
var request = new DocumentsRequest(settings);
Feed<Document> feed = request.GetEverything();
// this takes care of paging the results in
foreach (Document entry in feed.Entries)
{
AllDocuments.Add(entry);
if (entry.Type == Document.DocumentType.Document)
{
var fI = new FileInfo(@"somepath" + entry.DocumentId + ".doc");
if (!fI.Exists || fI.LastWriteTime < entry.Updated)
{
Debug.WriteLine("Download doc " + entry.DocumentId);
var type = Document.DownloadType.doc;
Stream stream = request.Download(entry, type);
if (fI.Exists) fI.Delete();
Stream file = fI.OpenWrite();
int nBytes = 2048;
int count = 0;
Byte[] arr = new Byte[nBytes];
do
{
count = stream.Read(arr, 0, nBytes);
file.Write(arr, 0, count);
} while (count > 0);
file.Flush();
file.Close();
stream.Close();
fI.CreationTimeUtc = entry.Updated;
fI.LastWriteTimeUtc = entry.Updated;
}
else
{
if (entry.Updated == fI.LastWriteTime)
{
Debug.WriteLine("Document up to date " + entry.DocumentId);
}
else
{
Debug.WriteLine(String.Format("Local version newer {0} [LOCAL {1}] [REMOTE {2}]", entry.DocumentId, fI.LastWriteTimeUtc, entry.Updated));
service.UploadDocument(fI.FullName, entry.Title);
}
}
}
}