コード例 #1
0
        public Stream GetSizeFileUrl(string URL, int pcodEmpresa, string pUserLogin, out int ReturnaTotalKb)
        {
            HttpWebRequest request = ((HttpWebRequest)WebRequest.Create(URL));
            Stream         StreamArchivo;
            int            totalBytes = 0;

            try
            {
                HttpWebResponse response = ((HttpWebResponse)request.GetResponse());
                using (StreamArchivo = response.GetResponseStream())
                {
                    using (Stream stream = StreamArchivo)
                    {
                        byte[] b = null;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            int count = 0;
                            do
                            {
                                byte[] buf = new byte[1024];
                                count = stream.Read(buf, 0, 1024);
                                ms.Write(buf, 0, count);
                                totalBytes += count;
                            }while (stream.CanRead && count > 0);
                            b          = ms.ToArray();
                            totalBytes = ms.ReadByte();
                        }
                        totalBytes = StreamArchivo.Read(b, 0, (int)b.Length);
                        totalBytes = stream.Read(b, 0, (int)b.Length);
                        int tota = stream.ReadByte();
                        totalBytes = (int)b.Length;
                    }
                }
            }
            catch (Exception ex)
            {
                HelpLogging.Write(TraceLevel.Error, this.GetType().Name + '.' + MethodBase.GetCurrentMethod().Name,
                                  ex, pUserLogin, pcodEmpresa.ToString());
                ReturnaTotalKb = totalBytes;
                return(null);
            }

            ReturnaTotalKb = totalBytes;

            return(StreamArchivo);
        }
コード例 #2
0
ファイル: StorageUtils.cs プロジェクト: ocarril/gh-sgpvdlls
        public static Stream getUrl(string URL, out int ReturnaTotalKb)
        {
            HttpWebRequest request = ((HttpWebRequest)WebRequest.Create(URL));
            Stream         StreamArchivo;
            int            totalBytes = 0;

            try
            {
                HttpWebResponse response = ((HttpWebResponse)request.GetResponse());
                using (StreamArchivo = response.GetResponseStream())
                {
                    //HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(string.Format(file, rutaDocumento, documentoPanel.NOMBRE_ARCHIVO));
                    //WebResponse myResp = myReq.GetResponse();
                    using (Stream stream = StreamArchivo)
                    {
                        byte[] b = null;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            int count = 0;
                            do
                            {
                                byte[] buf = new byte[1024];
                                count = stream.Read(buf, 0, 1024);
                                ms.Write(buf, 0, count);
                                totalBytes += count;
                            } while (stream.CanRead && count > 0);
                            b          = ms.ToArray();
                            totalBytes = ms.ReadByte();
                        }
                        totalBytes = StreamArchivo.Read(b, 0, (int)b.Length);
                        totalBytes = stream.Read(b, 0, (int)b.Length);
                        int tota = stream.ReadByte();
                        totalBytes = (int)b.Length;
                    }
                    // totalBytes = StreamArchivo.Read(b, 0, (int)b.Length);
                }
            }
            catch (Exception ex)
            {
                ReturnaTotalKb = totalBytes;
                return(null);
            }
            ReturnaTotalKb = totalBytes;
            return(StreamArchivo);
        }