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 {
      stream.Close();
    }

    return entry;
  }
}


21 comments:

Unknown 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?

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.

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

Unknown 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

Unknown 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

Unknown 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

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 "

Unknown said...

I find it very cool
welcom to website
cửa cuốn austdoor
cửa cuốn tự động
cửa cuốn nhanh
báo giá cửa cuốn chống cháy
giá 1 bộ cửa cuốn

Andrew303john said...

Economics Assignment Help

We Fullassignment.com is among the best companies on the Economics assignment help writing market. We offer top-notch essays, Public Economics Assignment help research papers, thesis and other types of works that can be assigned to you at a high school or college. We also provide Psychology Assignment help from our experts.

https://fullassignment.com/

hrroman said...

If you are looking for the Marketing Assignments help then in this case you can opt for our Market Analysis Assignment.we provide the best Assignment Help Experts.We also provide Market segmentation Assignment for students across the globe. for more information contact us +16692714848.

siva said...

The great thing about this post is quality information. I always like to read amazingly useful and quality content.
Your article is amazing, thank you for sharing this article.

Today Mobile Phone Offers
Mobile Phone Sale Offers
Mobile Offers Today
Mobile Phone Sale Offers
Today Mobile Phone Sale Offers
Mobile Phone Sale Offers

Please Keep On Sharing....

keith said...

Creative content thanks for sharing it
Canon Printer Error Code b204

Jon Hendo said...

The process of bidding for and winning global events and conferences can be a complex process. virtual edge and conference bios

Printer Repair City said...

Amazing, learn how to resolve Canon Printer Error u052 and solve canon printer error 6a81 Also canon printer error 5200 and this is good Canon Printer Error Code 1007 find out canon printer error e04 as well as canon printer error code p22