Update a document's content in .NET

class Demo {
  private DocumentsService service = null;

  public Demo() {
    service = new DocumentsService("google-DocUpdateTip-v1");
    service.setUserCredentials("username@gmail.com", "pa$$word");
    GDataGAuthRequestFactory reqFactory = (GDataGAuthRequestFactory)service.RequestFactory;
    reqFactory.ProtocolMajor = 3;

  static void Main(string[] args) {
    Demo demo = new Demo();

    // Fetch only documents
    DocumentsListQuery query = new DocumentsListQuery("http://docs.google.com/feeds/default/private/full/-/document");
    DocumentsFeed doclistFeed = demo.service.Query(query);

    // Update first document found
    DocumentEntry entry = (DocumentEntry)doclistFeed.Entries[0];
    Console.WriteLine("Updating " + entry.Title.Text + "...");

    DocumentEntry updatedEntry = demo.UpdateDocContents(entry, "C:/Documents and Settings/replacement.doc");
    Console.WriteLine(entry.Title.Text + " Updated!, view at " + entry.AlternateUri.ToString());

  public DocumentEntry UpdateDocContents(DocumentEntry entryToUpdate, String replacementFileName) {
    FileInfo fileInfo = new FileInfo(replacementFileName);
    FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

    DocumentEntry entry = null;

    try {
      // Convert the extension to caps and strip the "." off the front
      String ext = fileInfo.Extension.ToUpper().Substring(1);

      String contentType = (String)DocumentsService.GDocumentsAllowedTypes[ext];
      if (contentType == null) {
        throw new ArgumentException("File extension '" + ext + "' is not recognized as valid.");
      // Set ETag because we're making an update
      GDataRequestFactory factory = (GDataRequestFactory)service.RequestFactory;
      factory.CustomHeaders.Add("If-Match: " + entryToUpdate.Etag);

      Uri mediaUri = new Uri(entryToUpdate.MediaUri.ToString());
      entry = service.Update(mediaUri, stream, contentType, entryToUpdate.Title.Text) as DocumentEntry;
    } finally {

    return entry;


GDrive said...

small update:
instead of DocumentsService.GDocumentsAllowedTypes you need to put: DocumentsService.DocumentTypes[ext].

Besides that, the code runs without errors. However, if I look at the document in google docs, the old version appears. Any ideeas?

Shouldn't this code update the online document's content with the content from a local file?

Wonderful Jewelry said...

fashion jewelry wholesale
wholesale fashion jewelry
china jewelry wholesale
china fashion jewelry
jewelry wholesale china
fashion jewelry china
wholesale jewelry
jewelry wholesale

jhon apps said...

Mr Gdrive:
is that not giving good information ?

make facebook application

dongsheng said...

il la rponse est oui. La maison de couture fran?aise a confirm le modle Brit parce que le visage de cette collection de sacs Chanel Boy.

[Karl Lagerfeld] a le bguin au cours de cette unique, gal charismatique, qui est la fois un modle et un musicien, dans une sance photo tout l'heure, dit Chanel WWD Sac Hermès Evelyn. Cette alliance prcdemment imprvu est finalement devenu vident. Alice Dellal reprsente une incarnation idale de l', qui est unique autour de la collection de sacs Chanel Boy, qui s'efforce [d'tre] notions certainement pas conformistes de la fminit.

Yep, Dellal n'est pas vraiment conventionnelle. Ainsi que sa marque de fabrique de punk-rock uniforme, la petite de 24 ans est un batteur dans le mtal Grive bande et se rvlera tre trouv chahuter dans les rues base Londres avec Pixie Geldof. Shes loin de la blonde bombe Blake Lively, whos le visage en vigueur de Chanel Mademoiselle gamme, mais Lagerfeld est reconnu pour son go?t clectique, pralablement coule Lily Allen pour votre gamme de sac Cocoon en '09. En outre, l'androgynie Alice travaillera avec brio avec le 'Boy' collection. Comment rafra?chissante Sac Hermès Picotin.

Microsoft Office said...

Outlook 2010 provides you with a world-class experience to maintain your efficiency and keep in touch with personal and business networks. You can use download Outlook 2010, through a rich set of features and custom communication with one or more recipients.

kosovohp said...

Girl Xinh | Hot Girl | Cute Girl | Sexy Girl | Hot Girl Asian
Hot Girl | Lexi Belle | Sexy Girl | Cute Girl | Hot Asian Girl | Leah Dizon | Hot Girl Asian | Girl Xinh
socks proxy | socks5 | proxy free |proxy list

uknowme said...

il la rponse est oui. La maison de couture fran?aise a confirm le modle Brit parce que le visage de cette collection de sacs Chanel Boy. lohnrechner

top franchise opportunity

Cyntia Clara said...

Couldn't be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing! Info Aksesoris HP klik disini

Happy Group said...

chuyen la vay ne admin.

Xem Nè

Xem Tử vi hàng ngày

Tin tức tổng hợp

Xem phim cực hay

12 cung sao

Soi cầu lôto xổ số miền Bắc hằng ngày

Ảnh girl xinh, girl đẹp dễ thương, girl sexy, girl bikini

Giá Bắp Ngô

Giá Ca cao

Giá Cao su

Giá Hồ tiêu

Giá Cà phê

Giá Vàng JSC các loại

Tỷ giá ngoại tệ

Buồna quá đi

Happy Group said...

Diễn Đàn Rao Vặt
Rao Vặt Cấp Platinum
Rao Vặt Cấp Vàng Bạc Đá Quý
Rao vặt Linh Tinh
› Diễn đàn
Địa chỉ hay Địa điểm văn hóa
Địa chỉ hay Ảnh viện, áo cưới
Địa chỉ hay Khu vui chơi, giải trí
Địa chỉ hay Nhà hàng,khách sạn
Địa điểm khác
Bất Động Sản Nhà mặt phố
Bất Động Sản Đất vườn
Bất Động Sản Biệt thự, liền kề
Bất Động Sản Đất nền dự án

wdmtest said...

Why VB .NET?
What Is VB .NET?
What Can You Do with VB .NET?
Variables and Data Types
Declaring Variables and Constants
Data Types

Anonymous said...

instaeasy review
have Your Instagram liking, comment and engage automaticlly
instaeasy review
instaeasy review
engaging with audience 24 hours a day instaeasy review
instaeasy review
InstaEasyinstaeasy review
instaeasy review
Luke Maguire
insta easy review
instagram auto engagement tool
instaeasy review
the worlds leading instagram tool
instaeasy review
Make money made easy
instaeasy bonus
Thanks for reading

Sáng Nguyễn Tiến said...

I really thank the author of this article, the article has great significance for me, it just leads me to do better things for this life. Very meaningful, thank you very much, wish you happy
Mobimatic Review
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus
Vid Reaper Bonus
Mobimatic App Builder
Mobimatic Bonus

Mary Petter said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.

Aanaya said...

"Our only wish is that you get all kinds of goodness from us. Our service is available in-call and out call Hotel service. And all the girls we have to keep you happy and most decent high profile escort Service in Siliguri with excellent quality to vip decent independent escort girls ready for full satisfy all your requirements and full cooperative service giving you. Siliguri Escort Service,Call girl Service in Siliguri. Siliguri Escort Service
Siliguri Escort
Escort Service in Siliguri
Siliguri Escort Service Agency
Escort Siliguri
Call girl Service in Service "

Aanaya said...

"Bangalore Escorts high-class Model, Air-Hostess We offer Top class female Bangalore escorts North Indian, Punjabi, Gujarati model escorts in Bangalore Girlfriend Experience with North/South Indian Model Escort.These girls carry special essence with the natural aroma, which can simply amplify energy to men thoughts and can turn them on to get in a mood. These model escorts are multi-talented, they can make your time more lively by playing music, she can take a step with you and dances with you to live the moment completely. Bangalore Escort
Bangalore Escort Service
Bangalore Escort Service Agency
Escort Service in Bangalore
call girl service in Bangalore
Call girl in Bangalore
Adult Service in Bangalore "

Aanaya said...

" Surat Escort Service
Surat Escort
Surat Escort Service Ajency
Escort Service in Surat
Call Girl service in Surat
call gilr Surat surat escort service in surat 100% Safe & Secure High-Class Services Affordable Rate 100% Satisfaction, Unlimited Enjoyment. Any Time for Model/Teens Escort in Surat High-class luxury and premium escorts agency.high-class luxury and premium escorts agency We Provide Well Educated, Royal Class Female, High-class Escorts agency offering a top high-class escorts service in Surat, call girl service in Surat."

Aanaya said...

"Abu Dhabi Escoert Service , The Perfection of Pleasure Moulded by Pretty Model Abu dhabie Escort Service, call girl Abu Dhabi. Biggest escort directory of independent escorts, escort agencies and strip clubs in Abu Dhabi, UAE. You find here the best female and male escorts providing massage and escort services.Abu Dhabi Call girl service. Abu Dhabi Escort Service
Abu Dhabi Escort
Abu Dhabi Escort Service Ajency
Abu Dhabi Call girl Service
Escort Service in Abu Dhabi
call girl Abu Dhabi "

Aanaya said...

" Beauty Queen provides you high profile independent girl in Vadodara, escorts service in Vadodara, Vadodara escorts. If you are looking for the ultimate encounter in Vadodara then I am your sophisticated young Vadodara escorts service provides upscale companionship for making your night becomes true. Hot Collection Provide By Russian Escorts Indian Models Call Girls In Vadodara Enjoy Escorts Service, available in Vadodara 24/7*. Abu Dhabi Escort Service
Abu Dhabi Escort
Abu Dhabi Escort Service Ajency
Abu Dhabi Call girl Service
Escort Service in Abu Dhabi
call girl Abu Dhabi "