0

I am re-developing an app for a scanner used for stocktakes to allow it to work while offline. In order to do so, I need to be able to download a file from a laptop which is acting as a server. I got to a point at which it works, but only downloads that are of size 9.53mb max. How can I tweak the code to allow for larger files. I would need to allow for a maximum size of around 30mb.

Here is my code:

try
{
    string full_url = App.prouductUrl + App.stStocktakeId + ".db";

    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(full_url);
    httpRequest.Credentials = CredentialCache.DefaultCredentials;

    HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();

    System.IO.Stream dataStream = httpResponse.GetResponseStream();

    // Dim str As Stream = cdsMobileLibrary2.http_download.getfile(filename)

    //50 meg
    byte[] inBuf = new byte[10000001];
    int bytesToRead = Convert.ToInt32(inBuf.Length);
    int bytesRead = 0;
    while (bytesToRead > 0)
    {
        int n = dataStream.Read(inBuf, bytesRead, bytesToRead);
        if (n == 0)
        {
            break; // TODO: might not be correct. Was : Exit While
        }
        bytesRead += n;
        bytesToRead -= n;
    }
    FileStream fstr = new FileStream(@"\productdb\" + App.stStocktakeId + ".db", FileMode.OpenOrCreate, FileAccess.Write);
    fstr.Write(inBuf, 0, bytesRead);
    dataStream.Close();
    fstr.Close();
    string size = loginRes.getFromJSON("size");
    FileInfo fi = new FileInfo(@"\productdb\" + App.stStocktakeId + ".db");
    MessageBox.Show("File Size is:" + fi.Length + "Compared to:" + size);

}

catch { }     
ken2k
  • 48,145
  • 10
  • 116
  • 176
ArtleMaks
  • 151
  • 3
  • 19
  • 1
    maybe i missed something in the code logic but you have a buffer of 10000001 bytes outside the loop and that is the container of the data: 10000001 bytes ~ 9.53mb – Paolo Jun 13 '14 at 09:22
  • http://blogs.msdn.com/b/mikeormond/archive/2010/12/16/monitoring-memory-usage-on-windows-phone-7.aspx – Dhaval Patel Jun 13 '14 at 09:27
  • Possible duplicate of [compact framework download file from url](http://stackoverflow.com/questions/8996256/compact-framework-download-file-from-url) – Human_AfterAll May 15 '17 at 12:36

0 Answers0