[C#] WebResponce.GetResponseStream()

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by VISTALL, 12 May 2010.

  1. VISTALL

    VISTALL Banned

    Joined:
    3 May 2010
    Messages:
    16
    Likes Received:
    0
    Reputations:
    0
    Здраствуте у мну есть вот код

    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.

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

    .ATK Active Member

    Joined:
    20 Feb 2009
    Messages:
    143
    Likes Received:
    111
    Reputations:
    9
    WebClient wob=new WebClient();
    wob.DownloadFile(...,...);
     
  3. VISTALL

    VISTALL Banned

    Joined:
    3 May 2010
    Messages:
    16
    Likes Received:
    0
    Reputations:
    0

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