Use google docs in asp.net application

╄→尐↘猪︶ㄣ 提交于 2019-12-28 18:14:09

问题


How can I use GOOGLE DOCS in my project which I am doing using asp.net with C# as code behind.

Basically I need to display some pdf, doc,dox,excel documents in a read only form in the browser.

Thanks in advance


回答1:


Google docs has an API for that.

The Google Documents List Data API allows client applications to programmatically access and manipulate user data stored with Google Documents.

Check it's documentation, it has examples and everything you would need to develop something based on google docs.




回答2:


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();  
            }  

        }  
    }  
}  


来源:https://stackoverflow.com/questions/1566239/use-google-docs-in-asp-net-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!