Используйте Google Docs в приложении asp.net

Как я могу использовать GOOGLE DOCS в своем проекте, который я делаю, используя asp.net с C# в качестве кода позади.

В основном мне нужно отобразить некоторые документы pdf, doc,dox,excel в форме только для чтения в браузере.

заранее спасибо

2 ответа

Решение

У Google docs есть API для этого.

API данных Списка документов Google позволяет клиентским приложениям программно получать доступ к пользовательским данным, хранящимся в Документах Google, и манипулировать ими.

Посмотрите документацию, в ней есть примеры и все, что вам нужно для разработки чего-нибудь на основе документов Google.

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("username@gmail.com", "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();  
            }  

        }  
    }  
}  
Другие вопросы по тегам