Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   [C#] WebResponce.GetResponseStream() (https://forum.antichat.xyz/showthread.php?t=203371)

VISTALL 12.05.2010 00:15

[C#] WebResponce.GetResponseStream()
 
Здраствуте у мну есть вот код

PHP код:

              if (Status == Status.CANCEL)              {                  GoEnd(WordEnum.CANCEL_BY_USERtrue);                  return;              }                string path CurrentProperty.Path;              string fileName path file.FileName.Replace("/""\\") + ".zip";              var url = new Uri(CurrentProperty.listURL() + file.FileName ".zip");                var info = new FileInfo(fileName);                if (info.Directory != null)              {                  if (!info.Directory.Exists)                  {                      info.Directory.Create();                  }              }                //var client = new WebClient();               // Stream remoteStream = null;              int iRunningByteTotal = 0;              bool exception = true;                try              {                  WebRequest request = WebRequest.Create(url);                                   using (WebResponse response = request.GetResponse())                  {                      using (Stream remoteStream = response.GetResponseStream())                      {                          long iSize = response.ContentLength;                            using (Stream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write))                          {                              var byteBuffer = new byte[BUFFER_SIZE];                                string word = LanguageHolder.Instance()[WordEnum.DOWNLOADING_S1];                              MainForm.Instance.UpdateStatusLabel(String.Format(word, info.Name.Replace(".zip", "")));                                int oldPersent = 0;                              int iByteSize;                                while ((iByteSize = remoteStream.Read(byteBuffer, 0, byteBuffer.Length)) > 0)                              {                                  if (Status == Status.CANCEL)                                  {                                      GoEnd(WordEnum.CANCEL_BY_USER, false);                                      break;                                  }                                    fileStream.Write(byteBuffer, 0, iByteSize);                                  iRunningByteTotal += iByteSize;                                    var persent = (int)((100F * iRunningByteTotal) / iSize);                                  if (persent != oldPersent)                                  {                                      oldPersent = persent;                                      MainForm.Instance.UpdateProgressBar(persent, false);                                  }                              }                                exception = false;                          }                      }                  }              }              catch (WebException e)              {                  if (_log.IsDebugEnabled)                  {                      _log.Info("Exception[241]: " + e, e);                  }                  GoEnd(WordEnum.PROBLEM_WITH_INTERNET, true);                  return;              }              catch (Exception e)              {                  if (_log.IsDebugEnabled)                  {                      _log.Info("Exception[251]: " + e, e);                  }                  GoEnd(WordEnum.PROBLEM_WITH_SERVER, true);                  return;              } 


програма простенька сверяет файлы и потом качает.
Но оказалось странное...Когда вызывается WebResponce.GetResponseStream() выбрасывает бывает StackOverFlowException.

Вопрос ктото с таким стыкался....и Если ли другие класы для достании длины удаленного файла и потом для скачки....

.ATK 12.05.2010 00:29

WebClient wob=new WebClient();
wob.DownloadFile(...,...);

VISTALL 12.05.2010 13:15

Цитата:

Сообщение от .ATK
WebClient wob=new WebClient();
wob.DownloadFile(...,...);


спасибо, я хоть и знал)


Время: 06:09