Exemplo n.º 1
0
        public void WriteFiles()
        {
            String parentID = "1SAvLu-iPgghf7sksRo6LW7BYttXQzkxO";

            if (Request["parent"] != null)
            {
                parentID = Request["parent"];
            }

            CGDTool      gdt     = new CGDTool();
            DriveService service = gdt.Authenticate(Context);

            DriveFile[] files = gdt.GetFiles(service, parentID);

            foreach (DriveFile file in files)
            {
                Response.Write("<tr>");
//                Response.Write("<td>" + file.id + "</td>");
//                Response.Write("<td>" + file.parentID + "</td>");
                Response.Write("<td>" + file.simpleType + "</td>");
                Response.Write("<td>" + file.name + "</td>");
                Response.Write("<td>" + file.description + "</td>");

                String link = ".";
                switch (file.simpleType)
                {
                case "folder":
                    link = "./?parent=" + file.id;
                    break;

                case "image":
                    link = "gdimage.aspx?id=" + file.id + "&type=" + file.type;
                    break;

                case "doc":
                    link = "gddoc.aspx?id=" + file.id;
                    break;

                case "json":
                    link = "gdjson.aspx?id=" + file.id;
                    break;

                case "form":
                    link = "gdform.aspx?id=" + file.id;
                    break;

                case "mindmup":
                    link = "https://drive.mindmup.com/map/" + file.id;
                    break;
                }

                Response.Write("<td><a href='" + link + "'>Open</a></td>");
                Response.Write("<td>" + file.webViewLink + "</td>");
                Response.Write("</tr>");
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String id  = Request["id"];
            String url = "https://docs.google.com/forms/d/" + id + "/downloadresponses?tz_offset=7200000";

            url = "https://www.googleapis.com/drive/v3/files/171SteVTr-P8HtM5N5p8ftGFlEq_1LVQcTQ2p9yMUmDY";



            CGDTool      gdt     = new CGDTool();
            DriveService service = gdt.Authenticate(Context);

            service.HttpClientInitializer.Initialize(service.HttpClient);

            Task <byte[]> t = service.HttpClient.GetByteArrayAsync(url);


            string result = System.Text.Encoding.UTF8.GetString(t.Result);

            Response.Write(result);
        }
Exemplo n.º 3
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            CGDTool      gdt          = new CGDTool();
            DriveService driveService = gdt.Authenticate(context);

            var fileId = id;

            try
            {
                if (export)
                {
                    var request = driveService.Files.Export(fileId, this.mimetype);
                    var stream  = new System.IO.MemoryStream();
                    request.MediaDownloader.ProgressChanged +=
                        (IDownloadProgress progress) =>
                    {
                        switch (progress.Status)
                        {
                        case DownloadStatus.Downloading:
                        {
                            UpateStatus("bytes" + progress.BytesDownloaded, false);
                            break;
                        }

                        case DownloadStatus.Completed:
                        {
                            data = stream.ToArray();
                            UpateStatus("Download complete", true);
                            break;
                        }

                        case DownloadStatus.Failed:
                        {
                            UpateStatus("Download failed: " + progress.Exception.Message, true);
                            break;
                        }
                        }
                    };
                    request.Download(stream);
                }
                else
                {
                    var stream = new System.IO.MemoryStream();

                    // https://docs.google.com/forms/d/171SteVTr-P8HtM5N5p8ftGFlEq_1LVQcTQ2p9yMUmDY/downloadresponses?tz_offset=7200000

                    Google.Apis.Drive.v3.FilesResource.GetRequest request = driveService.Files.Get(fileId);

                    request.MediaDownloader.ProgressChanged +=
                        (IDownloadProgress progress) =>
                    {
                        switch (progress.Status)
                        {
                        case DownloadStatus.Downloading:
                        {
                            UpateStatus("bytes" + progress.BytesDownloaded, false);
                            break;
                        }

                        case DownloadStatus.Completed:
                        {
                            data = stream.ToArray();
                            UpateStatus("Download complete", true);
                            break;
                        }

                        case DownloadStatus.Failed:
                        {
                            UpateStatus("Download failed 1: " + progress.Exception.Message, true);
                            break;
                        }
                        }
                    };



                    request.Alt = Google.Apis.Drive.v3.DriveBaseServiceRequest <Google.Apis.Drive.v3.Data.File> .AltEnum.Json;
                    request.Download(stream);
                }
            }
            catch (Exception err)
            {
                UpateStatus("Download failed 2: " + err.Message, true);
            }
        }