Example #1
0
        private bool SendFile(string uriUpload, string htmlBuf)
        {
            try
            {
                Uri uri = new Uri(uriUpload);
                Console.WriteLine("uri in send: " + uri);
                string[]         token        = uri.UserInfo.Split(':');
                string           filename     = "Report Floading " + DateTime.Now.ToString("dd-MM-yyyy hh.ss") + ".html";
                string           fullPathName = StorageManager.getEnvValue("wrDirectory") + filename;
                DocumentsService service      = new DocumentsService("Floading report");
                Console.WriteLine("token[0] in send: " + token[0] + " token[1] in send: " + token[1]);
                service.setUserCredentials(token[0], token[1]);
                FileStream stream    = new FileStream(fullPathName, FileMode.CreateNew, FileAccess.Write);
                byte[]     htmlBytes = new System.Text.ASCIIEncoding().GetBytes(htmlBuf);
                stream.Write(htmlBytes, 0, htmlBytes.Length);
                stream.Close();
                DocumentsListQuery query = new DocumentsListQuery();
                DocumentsFeed      feed  = service.Query(query);

                DocumentEntry newEntry = service.UploadDocument(fullPathName, filename);

                File.Delete(fullPathName);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        public static void TrashDocument(GDocsAbstractItem item)
        {
            // Search for document(s) having exactly the title,
            // Delete the one with matching AlternateUri
            DocumentsListQuery query = new DocumentsListQuery();

            query.Title      = item.Name;
            query.TitleExact = true;
            DocumentsFeed docFeed  = service.Query(query);
            DocumentEntry document =
                docFeed.Entries.FirstOrDefault(e => e.AlternateUri == item.URL) as DocumentEntry;

            if (document == null)
            {
                return;
            }

            try {
                document.Delete();
            } catch (Exception e) {
                Log.Error(e.Message);
                Services.Notifications.Notify(GetDeleteDocumentFailedNotification());
                return;
            }

            Services.Notifications.Notify(GetDocumentDeletedNotification(item.Name));
        }
Example #3
0
        /// <summary>
        /// Fetches list of documents in Google Drive.
        /// </summary>
        /// <returns></returns>
        public static DocumentsFeed GetGDriveDocList()
        {
            //Waiting for the service authentication to complete.
            _autoEvent.WaitOne();
            DocumentsFeed documents = null;

            try
            {
                //In case an error was encountered go back.
                if (_parameters == null || _exception != null)
                {
                    return(documents);
                }
                //Creating the request factory for the Drive service.
                GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, APPLICATION_NAME, _parameters);
                //Creating a service instance.
                DocumentsService service = new DocumentsService(APPLICATION_NAME);
                //Assigning the factory instance to the service.
                service.RequestFactory = requestFactory;
                DocumentsListQuery query = new DocumentsListQuery();
                //Sending a query to the service to fetch list of all documents on the drive.
                documents = service.Query(query);
            }
            catch (Exception Ex)
            {
                _exception = Ex;
            }
            finally
            {
                //Can now signal other threads to continue accessing/refreshing services.
                _autoEvent.Set();
            }
            return(documents);
        }
Example #4
0
        private int countFoldersAndFiles(DocumentEntry folder)
        {
            if (cancel())
            {
                return(0);
            }
            int         count        = 1;
            FolderQuery contentQuery = new FolderQuery(folder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (cancel())
                {
                    return(0);
                }
                if (!entry.IsFolder)
                {
                    if (m_fileFilters.ContainsKey(Path.GetExtension(entry.Title.Text)))
                    {
                        count++;
                    }
                }
                else
                {
                    count += countFoldersAndFiles(entry);
                }
            }
            return(count);
        }
Example #5
0
        public List <ISPCItem> GetItems(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCItem> items = new List <ISPCItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCItem item = new GItem(siteSetting, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
Example #6
0
        public List <ISPCFolder> GetFolders(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCFolder>  folders = new List <ISPCFolder>();
            DocumentsListQuery query   = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            query.ShowFolders = true;
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCFolder folder = new GFolder(siteSetting, entry.ResourceId, entry.Title.Text, entry.Id.AbsoluteUri);
                    folders.Add(folder);
                }
            }
            return(folders);
        }
Example #7
0
        public void InitWorkbook(string workbookName, string uploadTemplatePath)
        {
            DocumentsFeed docs  = documentService.Query(new DocumentsListQuery());
            DocumentEntry entry = null;

            foreach (DocumentEntry doc in docs.Entries)
            {
                if (!doc.IsSpreadsheet)
                {
                    continue;
                }

                if (doc.Title.Text == workbookName)
                {
                    entry = doc;
                    break;
                }
            }
            if (entry == null)
            {
                documentService.UploadDocument(uploadTemplatePath, null);
            }
            else
            {
                ClearSheet(workbookName);
            }
        }
Example #8
0
        public List <IItem> GetListItems(ISiteSetting siteSetting, string webUrl, string listName, bool isRecursive)
        {
            Login(siteSetting.Username, siteSetting.Password);
            List <IItem> items = new List <IItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (string.IsNullOrEmpty(webUrl) == false)
            {
                query = new FolderQuery(webUrl);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (String.IsNullOrEmpty(webUrl) == true)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    IItem item = new GItem(siteSetting.ID, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    item.Properties.Add("ows_Editor", entry.LastModified.Name);
                    item.Properties.Add("ows_Modified", entry.Edited.DateValue.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
        /// <summary>
        /// Retrieves a list of documents from the server.
        /// </summary>
        /// <returns>The list of documents as a DocumentsFeed.</returns>
        public DocumentsFeed GetDocs()
        {
            DocumentsListQuery query = new DocumentsListQuery();
            DocumentsFeed      feed  = service.Query(query);

            return(feed);
        }
        protected override void LoadData()
        {
            //Fetching user's Google drive document list.
            DocumentsFeed feed = ServicesModel.GetGDriveDocList();

            //Checking for errors in Model class
            if (ServicesModel.Error != null)
            {
                //Displaying error to user
                MessageBox.Show(ServicesModel.Error.Message + ".\n Please recheck the access code you've entered.", "Error accessing the service");
                //Clearing the error
                ServicesModel.Error = null;
                //Reenabling submit and disabling refresh
                _canSubmit  = true;
                _canRefresh = false;
                return;
            }

            if (feed != null)
            {
                //Creating a temporary collection on the worker thread to avoid cross-thread exceptions.
                //This will keep the UI responsive while the thread iterates over the document list.
                ObservableCollection <string> temp = new ObservableCollection <string>();
                foreach (var entry in feed.Entries)
                {
                    temp.Add(entry.Title.Text);
                }
                //Assiging this collection to the Data collection bound to the View.
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { Data = temp; }));
            }
        }
Example #11
0
        public DocumentsFeed GetFolderList(string folderID)
        {
            FolderQuery query = new FolderQuery(folderID);

            query.ShowFolders = false;
            DocumentsFeed feed = service.Query(query);

            return(feed);
        }
Example #12
0
        /// <summary>
        /// Retrieves a list of documents from the server.
        /// </summary>
        /// <returns>The list of documents as a DocumentsFeed.</returns>
        public DocumentsFeed GetDocs()
        {
            DocumentsListQuery query = new DocumentsListQuery();

            query.ShowFolders = true;

            DocumentsFeed feed = service.Query(query);

            return(feed);
        }
Example #13
0
        private void downloadDirectory(DocumentEntry folder, string downloadTo)
        {
            if (cancel())
            {
                return;
            }
            string currentFolderName = Path.Combine(downloadTo, folder.Title.Text);

            Directory.CreateDirectory(currentFolderName);
            reportProgress("Dowloaded/Updated " + folder.Title.Text);
            FolderQuery contentQuery = new FolderQuery(folder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (cancel())
                {
                    return;
                }
                if (!entry.IsFolder)
                {
                    if (m_fileFilters.ContainsKey(Path.GetExtension(entry.Title.Text)))
                    {
                        string downloadUrl = entry.Content.Src.Content;
                        if (cancel())
                        {
                            return;
                        }
                        Stream stream = m_service.Query(new Uri(downloadUrl));
                        if (cancel())
                        {
                            return;
                        }
                        string     fileName         = Path.Combine(currentFolderName, entry.Title.Text);
                        FileStream outputFileStream = new FileStream(fileName, FileMode.Create);
                        stream.CopyTo(outputFileStream);
                        outputFileStream.Close();
                        reportProgress("Downloaded/Updated " + entry.Title.Text);
                        if (cancel())
                        {
                            return;
                        }
                    }
                }
                else
                {
                    downloadDirectory(entry, currentFolderName);
                }
            }
        }
Example #14
0
        public void GoogleDocsList()
        {
            DocumentsListQuery query     = new DocumentsListQuery();
            DocumentsService   myService = new DocumentsService("exampleCo-exampleApp-1");

            myService.setUserCredentials("gianpieroradano", "");
            DocumentsFeed feed = myService.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                Console.WriteLine(entry.Title.Text);
            }
        }
Example #15
0
        /// <summary>
        /// Gets a new list of documents from the server and renders
        /// them in the ListView called DocList on the form.
        /// </summary>
        public void UpdateDocList()
        {
            if (!modelGoogle.loggedIn)
            {
                MessageBox.Show("Log in before retrieving documents.", "Log in", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DocList.Items.Clear();
            tvGoogle.Nodes.Clear();

            try
            {
                DocumentsFeed feed = modelGoogle.GetDocs();

                foreach (DocumentEntry entry in feed.Entries)
                {
                    string imageKey = "";
                    if (entry.IsDocument)
                    {
                        imageKey = "Document.gif";
                    }
                    else if (entry.IsSpreadsheet)
                    {
                        imageKey = "Spreadsheet.gif";
                    }
                    else
                    {
                        imageKey = "Presentation.gif";
                    }

                    ListViewItem item = new ListViewItem(entry.Title.Text, imageKey);
                    item.SubItems.Add(entry.Updated.ToString());
                    item.Tag = entry;
                    DocList.Items.Add(item);
                }


                foreach (ColumnHeader column in DocList.Columns)
                {
                    column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                }


                ModelGoogle.LoadGoogleDocsInTree(tvGoogle, feed);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error retrieving documents: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #16
0
        public string getSpreadsheetURL(string sheetName)
        {
            DocumentsService docService = new DocumentsService(this.googleAppName);

            docService.RequestFactory = GoogleOauthAccess.getRequestFactory(this.googleAppName, this.parameters);

            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

            DocumentsListQuery docQuery = new DocumentsListQuery();

            docQuery.Title = sheetName;

            DocumentsFeed feed  = docService.Query(docQuery);
            DocumentEntry entry = (DocumentEntry)feed.Entries[0];

            return("https://docs.google.com/spreadsheet/ccc?key=" + entry.ResourceId.Replace("spreadsheet:", ""));
        }
Example #17
0
        static public void send(String email, String password)
        {
            DocumentsService service = new DocumentsService("servizioEsempio");

            service.setUserCredentials(email, password);
            DocumentsListQuery query = new DocumentsListQuery();
            DocumentsFeed      feed  = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                Console.WriteLine(entry.Title.Text);
            }
            System.Console.ReadLine();

            // DocumentEntry newEntry = service.UploadDocument("C:\\Users\\gianpy\\Desktop\\specifiche.txt", "New Document Title.txt");
            // Console.WriteLine("Now accessible at: " + newEntry.AlternateUri.ToString());
        }
Example #18
0
        private DocumentEntry findFolder(string folderName, DocumentEntry parentFolder = null)
        {
            if (cancel())
            {
                return(null);
            }
            FolderQuery query = (parentFolder == null ? new FolderQuery() : new FolderQuery(parentFolder.ResourceId));

            query.TitleExact = true;
            query.Title      = folderName;
            DocumentsFeed feed = m_service.Query(query);

            if (feed.Entries.Count == 0)
            {
                return(null);
            }
            return((DocumentEntry)feed.Entries[0]);
        }
Example #19
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Documents List Authentication Test");

            DocumentsListQuery query   = new DocumentsListQuery();
            DocumentsService   service = new DocumentsService(this.ApplicationName);

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }
            service.RequestFactory = this.factory;

            DocumentsFeed feed = service.Query(query) as DocumentsFeed;

            ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("AuthenticationTest"));
            service.Credentials = null;
        }
Example #20
0
        private void getListOfFoldersInternal(string downloadFrom)
        {
            listOfFolders = new List <string>();
            DocumentEntry parentFolder = locateFolder(downloadFrom, null);

            if (!string.IsNullOrWhiteSpace(downloadFrom) && parentFolder == null)
            {
                return;
            }
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (entry.IsFolder)
                {
                    listOfFolders.Add(entry.Title.Text);
                }
            }
        }
Example #21
0
        public static void LoadGoogleDocsInTree(TreeView tvGoogle, DocumentsFeed feed)
        {
            // Create folders first
            //
            foreach (DocumentEntry entry in feed.Entries)
            {
                if (!entry.IsFolder)
                {
                    continue;
                }

                int image         = 0;
                int imageSelected = 0;

                image         = FCMConstant.Image.Folder;
                imageSelected = FCMConstant.Image.Folder;

                TreeNode tn = new TreeNode(entry.Title.Text, image, imageSelected);

                tvGoogle.Nodes.Add(tn);
                tn.Tag = entry;
            }


            // Load documents
            //


            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder)
                {
                    continue;
                }

                TreeNode parent = new TreeNode();
                parent = tvGoogle.Nodes[0];

                foreach (var folder in entry.ParentFolders)
                {
                    foreach (TreeNode tn in tvGoogle.Nodes)
                    {
                        if (tn.Text == folder.Title)
                        {
                            parent = tn;
                        }
                    }
                }


                int image         = 0;
                int imageSelected = 0;

                string documentType = MackkadoITFramework.Helper.Utils.DocumentType.WORD;

                if (entry.IsFolder)
                {
                    documentType  = MackkadoITFramework.Helper.Utils.DocumentType.FOLDER;
                    image         = FCMConstant.Image.Folder;
                    imageSelected = FCMConstant.Image.Folder;
                }
                else
                {
                    if (entry.IsDocument)
                    {
                        documentType  = MackkadoITFramework.Helper.Utils.DocumentType.WORD;
                        image         = FCMConstant.Image.Document;
                        imageSelected = FCMConstant.Image.Document;
                    }
                    else
                    {
                        if (entry.IsSpreadsheet)
                        {
                            documentType  = Utils.DocumentType.EXCEL;
                            image         = FCMConstant.Image.Excel;
                            imageSelected = FCMConstant.Image.Excel;
                        }
                        else
                        {
                            if (entry.IsPDF)
                            {
                                documentType  = MackkadoITFramework.Helper.Utils.DocumentType.PDF;
                                image         = FCMConstant.Image.PDF;
                                imageSelected = FCMConstant.Image.PDF;
                            }
                        }
                    }
                }

                TreeNode child = new TreeNode(entry.Title.Text, image, imageSelected);
                child.Tag = entry;

                parent.Nodes.Add(child);
            }

            return;
        }
Example #22
0
        public void uploadFile(string fileName, DocumentEntry parentFolder)
        {
            if (cancel())
            {
                return;
            }
            string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

            if (!m_fileFilters.ContainsKey(fileExtension))
            {
                return;
            }
            int CHUNK_SIZE       = 1;
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Check if entry exists
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.Title      = Path.GetFileName(fileName);
            contentQuery.TitleExact = true;
            DocumentsFeed contents   = m_service.Query(contentQuery);
            bool          fileExists = contents.Entries.Count > 0;
            DocumentEntry entry      = fileExists?contents.Entries[0] as DocumentEntry:new DocumentEntry();

            entry.Title.Text = Path.GetFileName(fileName);
            string mimeType = m_fileFilters[fileExtension];

            entry.MediaSource = new MediaFileSource(fileName, mimeType);
            // Define the resumable upload link
            string notConvert = "?convert=false";
            Uri    createUploadUrl;

            if (parentFolder == null)
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full" + notConvert);
            }
            else
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full/" + parentFolder.ResourceId + "/contents" + notConvert);
            }
            AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);

            // Set the service to be used to parse the returned entry
            entry.Service = m_service;

            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Set the handlers for the completion and progress events
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
            uploader.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(OnProgress);
            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("uploader", ServiceNames.Documents, m_username, m_password);

            // Start the upload process
            if (cancel())
            {
                return;
            }
            if (fileExists)
            {
                uploader.UpdateAsync(cla, entry, new Object());
            }
            else
            {
                uploader.InsertAsync(cla, entry, new Object());
            }
        }
        public void parse()
        {
            //The date and time in this moment.
            DateTime timeNow = DateTime.Now;

            //Indicate if there are new updates in Google Docs.
            bool isNewUpdate = false;
            //The title of the most recent updated document.
            string latestEditedTitle = "";
            //The number of documents in total.
            int numOfDocuments = 0;
            //The number of unviewed documents.
            int unviewedDocuments = 0;

            //Inform the GUI to change the progress value.
            UpdateProgressBar(25);

            try
            {
                //Download the feed from Google Docs server.
                DocumentsListQuery query = new DocumentsListQuery();
                DocumentsFeed      feed  = _myService.Query(query);

                //Inform the GUI to change the progress value.
                UpdateProgressBar(50);

                foreach (DocumentEntry entry in feed.Entries)
                {
                    DateTime lastEditedTime = new DateTime(); //No use for now.
                    DateTime lastViewedTime = timeNow;
                    //Note: There are some Google Docs type has no lastViewed tag.
                    //      Hence, it is better to set the default value of the
                    //      lastViewedTime to be the current date and time.

                    //Retrieve lastEditedTime and lastViewedTime from
                    //the Extension Elements of the feeds.
                    HandleExtensionElements(entry, ref lastEditedTime, ref lastViewedTime);

                    //If the document is newly created document or unread updated document...
                    if (VerifyNewDocuments(entry) || VerifyUnviewedUpdatedDocuments(entry, lastViewedTime))
                    {
                        HandleNewOrUnreadUpdatedDocuments(
                            entry,
                            ref isNewUpdate, ref latestEditedTime,
                            ref latestEditedTitle, ref unviewedDocuments);
                    }

                    //Inform the GUI to change the progress value.
                    UpdateProgressBar(((int)(((double)numOfDocuments++ / feed.Entries.Count()) * 50)) + 50);
                }

                //Inform the GUI to change the status message.
                UpdateStatusMessage(unviewedDocuments.ToString() + " documents listed above.");

                //Inform the GUI to update and show the balloon tooltip.
                updateNotifyIcon(
                    "Your Google Docs is updated",
                    "Latest edited document: " + latestEditedTitle,
                    unviewedDocuments,
                    isNewUpdate);
            }
            catch (Google.GData.Client.InvalidCredentialsException)
            {
                throw;
            }
            catch (Google.GData.Client.CaptchaRequiredException)
            {
                throw;
            }
            catch (Google.GData.Client.AuthenticationException)
            {
                throw;
            }
            catch (Exception)
            {
                //Inform the GUI to change the status message.
                UpdateStatusMessage("Unable to connect to Google Docs server.");

                //Inform the GUI to UPDATE ONLY the balloon tooltip icon
                //and say there is no new update found.
                updateNotifyIcon(
                    "",
                    "",
                    0,
                    false);
            }
        }
Example #24
0
        static void Main(string[] args)
        {
            var localHtmlDocname = "docContents.htm";

            //Get credentials
            Console.Write("Enter your username:"******"Enter your password:"******"my-service");

            service.setUserCredentials(user, password);
            DocumentsFeed      listFeed = null;
            AtomFeed           feed     = null;
            DocumentsListQuery query    = null;
            IProgress <string> p        = new Progress <string>(Console.WriteLine);

            //Get list of documents
            var getList = Task.Run(() =>
            {
                p.Report("Reading list of documents");
                query = new DocumentsListQuery();
                feed  = service.Query(query);
            });

            getList.Wait();

            foreach (DocumentEntry entry in feed.Entries.OrderBy(x => x.Title.Text))
            {
                if (entry.IsDocument)
                {
                    Console.WriteLine(entry.Title.Text);
                }
            }

            Console.WriteLine("Type the name of the document you would like to open:");
            var    openDocTitle = Console.ReadLine();
            string contents     = string.Empty;

            //Get list of documents
            var openDoc = Task.Run(() =>
            {
                p.Report("Reading document contents");
                query.Title = openDocTitle;
                feed        = service.Query(query);

                var openMe = feed.Entries[0] as DocumentEntry;
                var stream = service.Query(new Uri(openMe.Content.Src.ToString()));
                var reader = new StreamReader(stream);
                contents   = reader.ReadToEnd();

                using (var fs = File.Create(localHtmlDocname))
                {
                    using (var writer = new StreamWriter(fs))
                    {
                        contents += Environment.UserName + " was here - " + DateTime.Now.ToString() + "<br/>";
                        writer.Write(contents);
                        writer.Flush();
                        writer.Close();
                    }

                    fs.Close();
                }

                //OPTIONAL: Uncomment to save changes BACK to the google doc

                /*
                 * openMe.MediaSource = new MediaFileSource(localHtmlDocname, "text/html");
                 * var uploader = new ResumableUploader();
                 *
                 * //Get an authenticator
                 * var authenticator = new ClientLoginAuthenticator("document-access-test", ServiceNames.Documents, service.Credentials);
                 *
                 * //Perform the upload...
                 * Console.WriteLine("Saving to Google Drive...");
                 * uploader.Update(authenticator, openMe);
                 */
            });

            openDoc.Wait();
            Console.WriteLine("Opening contents of Google doc file...");
            System.Diagnostics.Process.Start(localHtmlDocname);
        }