2009-10-14 49 views
6

Làm cách nào tôi có thể sử dụng GOOGLE DOCS trong dự án của mình mà tôi đang thực hiện bằng cách sử dụng asp.net với C# làm mã phía sau.Sử dụng tài liệu google trong ứng dụng asp.net

Về cơ bản tôi cần hiển thị một số tài liệu pdf, doc, dox, excel ở dạng chỉ đọc trong trình duyệt.

Cảm ơn trước

Trả lời

3

Tài liệu của Google có API cho điều đó.

API dữ liệu danh sách Google Documents cho phép ứng dụng khách truy cập theo chương trình và thao tác dữ liệu người dùng được lưu trữ với Google Documents.

Kiểm tra xem documentation, nó có các ví dụ và mọi thứ bạn cần để phát triển thứ gì đó dựa trên tài liệu google.

1
using System; 
using System.IO; 
using System.Net; 
using Google.Documents; 
using Google.GData.Client; 

namespace Google 
{ 
    class Program 
    { 
     private static string applicationName = "Testing"; 

     static void Main(string[] args) 
     { 
      GDataCredentials credentials = new GDataCredentials("[email protected]", "password"); 
      RequestSettings settings = new RequestSettings(applicationName, credentials); 
      settings.AutoPaging = true; 
      settings.PageSize = 100; 
      DocumentsRequest documentsRequest = new DocumentsRequest(settings); 
      Feed<document> documentFeed = documentsRequest.GetDocuments(); 
      foreach (Document document in documentFeed.Entries) 
      { 
       Document.DownloadType type = Document.DownloadType.pdf; 

       Stream downloadStream = documentsRequest.Download(document, type); 

       Stream fileSaveStream = new FileStream(string.Format(@"C:\Temp\{0}.pdf", document.Title), FileMode.CreateNew); 

       if (fileSaveStream != null) 
       { 
        int nBytes = 2048; 
        int count = 0; 
        Byte[] arr = new Byte[nBytes]; 

        do 
        { 
         count = downloadStream.Read(arr, 0, nBytes); 
         fileSaveStream.Write(arr, 0, count); 

        } while (count > 0); 
        fileSaveStream.Flush(); 
        fileSaveStream.Close(); 
       } 
       downloadStream.Close(); 
      } 

     } 
    } 
} 
Các vấn đề liên quan