Implementing Progress Bar in FileStream

Sep 14 2011 4:45 PM
I have a code that downloads the file from SQL Server Database, and save it into the target location : 

            SqlConnection conn = new SqlConnection(string.Format("server=xslogic-pc; uid=sa; pwd=hotmail; database=files"));
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Files WHERE(status IS NULL) order by id", conn);
            adapter.Fill(dataSet1.Tables[0]);

            string tempDir = Path.GetTempPath();
            if (dataSet1 != null && dataSet1.Tables.Count > 0 && dataSet1.Tables[0].Rows.Count > 0)
            {
                DataRow row = dataSet1.Tables[0].Rows[0];  // If you go sorting the columns, you may need to change this
                fileid = row["id"].ToString();
                Class1.InsertValue("update files set status = '1' where id = '" + fileid + "'");
                filename = (string)row["OriginalName"];
                lbldownload.Text = "Downloading file : " + filename;
                LaunchedFile = tempDir + filename;                             // Get our new Filename and path
                FileInfo fi = new FileInfo(LaunchedFile);                      // Get our hands around the file specification   
                FileStream fs = fi.Create();                                   // Create the new file
                byte[] Data = new byte[0];                                     // Instantiate a buffer to hold the data   
                Data = (byte[])row["FileData"];                                // Load the buffer

                int ArraySize = new int();                                     // Find the Size of the buffer (aka file)
                ArraySize = Data.GetUpperBound(0);
                fs.Write(Data, 0, ArraySize);                                  // Write the file to disk. If a really large file, then braek it up

                fs.Flush();                                                    // Flush the bytes to the disk   
                fs.Close();                                                    // Close the file.

                File.Move(LaunchedFile, @"D:\\Zeeshan\\Transmission\\to\\" + filename);
                Class1.InsertValue("update files set status = '2' where id = '" + fileid + "'");

                lbldownload.Text = "Downloading file : " + filename + "  -  COMPLETED";
                fileid = "";
                filename = "";
                adapter.Dispose();
                dataSet1.Clear();


my above given code works perfectly, i just want to implement a  progress bar in my application so that i can have a look that how much file downloading is left....

can anyone help me out with this...