Esempio n. 1
0
        internal void GetFile(DownloadFile downloadFile)
        {
            BinaryReader br = null;
            BinaryWriter bw = null;
            WebResponse response = null;

            try
            {
                // Request
                var request = (HttpWebRequest)WebRequest.Create(downloadFile.Uri);
                request.Method = "GET";
                request.AllowWriteStreamBuffering = false;
                request.KeepAlive = false;
                request.Timeout = 300000;
                var cookie = new Cookie("TICKET", downloadFile.Ticket);
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(new System.Uri(downloadFile.Uri), cookie);

                // Response
                response = request.GetResponse();
                var responseStream = response.GetResponseStream();

                // Write file
                if (!Directory.Exists(downloadFile.Path))
                {
                    Directory.CreateDirectory(downloadFile.Path);
                }
                br = new BinaryReader(responseStream);
                bw = new BinaryWriter(File.Create(downloadFile.Path + @"\" + downloadFile.File));
                bw.Write(br.ReadBytes((int)response.ContentLength));
                bw.Flush();
            }
            finally
            {
                if (bw != null) bw.Close();
                if (br != null) br.Close();
                if (response != null) response.Close();
            }
        }
Esempio n. 2
0
        public void DownloadFile(string columnName, string path, int versionId)
        {
            var index = GetColumnIndex(columnName);
            var field = _fields[_fields.IndexOf(new QField(Columns[index].ColumnId))];
            var fileName = field.Value;

            var fileToDownload = new DownloadFile(Application.Client.Ticket, Application.Client.AccountDomain, path, fileName, Table.TableId, RecordId,
                                                           field.FieldId, versionId);
            fileToDownload.Get();
        }