Download function not showing total size of file, while downloading
<pre><code>protected void downloadFunction(string filename)
{
    string filepath = @"D:\XtraFiles\" + filename;
    string contentType = "application/x-newton-compatible-pkg";

    Stream iStream = null;
    // Buffer to read 1024K bytes in chunk
    byte[] buffer = new Byte[1048576];

    // Length of the file:
    int length;
    // Total bytes to read:
    long dataToRead;

    try
    {
        // Open the file.
        iStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);

        // Total bytes to read:
        dataToRead = iStream.Length;
        HttpContext.Current.Response.ContentType = contentType;
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));

        // Read the bytes.
        while (dataToRead &gt; 0)
        {
            // Verify that the client is connected.
            if (HttpContext.Current.Response.IsClientConnected)
            {
                // Read the data in buffer.
                length = iStream.Read(buffer, 0, 10000);

                // Write the data to the current output stream.
                HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);

                // Flush the data to the HTML output.
                HttpContext.Current.Response.Flush();

                buffer = new Byte[10000];
                dataToRead = dataToRead - length;
            }
            else
            {
                //prevent infinite loop if user disconnects
                dataToRead = -1;
            }
        }
    }
    catch (Exception ex)
    {
        // Trap the error, if any.
        HttpContext.Current.Response.Write("Error : " + ex.Message + "&lt;br /&gt;");
        HttpContext.Current.Response.ContentType = "text/html";
        HttpContext.Current.Response.Write("Error : file not found");
    }
    finally
    {
        if (iStream != null)
        {
            //Close the file.
            iStream.Close();
        }
        HttpContext.Current.Response.End();
        HttpContext.Current.Response.Close();
    }
}
</code></pre>

<p>My donwload function is working perfect, but when users are downloading the browser cant see the total file size of the download.</p>

<p>So now the browser says eq. Downloading 8mb of ?, insted of Downloading 8mb of 142mb.</p>

<p>What have i missed?</p>
