开发者

It is possible to load in web .net actual file from acount google using google docs?

开发者 https://www.devze.com 2023-04-11 23:27 出处:网络
In my web project web .net I try to implement google docs. I upload any MS office document and view it on telerik window by open window sets url: entry.AlternateUri.ToString()

In my web project web .net I try to implement google docs. I upload any MS office document and view it on telerik window by open window sets url: entry.AlternateUri.ToString()

Then I try to download file (if title is match) to local:

   myService = new DocumentsService("exampleCo-exampleApp-1");
   myService.setUserCredentials(开发者_StackOverflow"name_my_mail@gmail.com", "pass");
   DocumentsListQuery query = new DocumentsListQuery();
   DocumentsFeed feed = myService.Query(query);                   

                    foreach (DocumentEntry entry in feed.Entries)
                    {
                        if (entry.Title.Text == "temp.docx")
                        {
                            Uri documentUri = new Uri(entry.Content.AbsoluteUri);

                            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(documentUri);
                            GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)myService.RequestFactory;
                            webRequest.Headers.Add("Authorization", "GoogleLogin auth=" + factory.GAuthToken);

                            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
                            StreamWriter streamWriter = new StreamWriter("D:\\temp.txt");

                            string line = "";
                            while( (line = streamReader.ReadLine()) != null) {

                                   streamWriter.WriteLine(line);
                            }
                            streamReader.Close();
                            streamWriter.Close();  
                        }
                    }

But file temp.txt contents actual html code of content file fron google acount.


You might wanna check out Google Docs API.

DotNet API

General Google Docs API

Hope that helps

Cheers

Sascha

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号