Esempio n. 1
0
 void uploadStreamWithProgress_ProgressChanged(object sender, StreamWithProgress.ProgressChangedEventArgs e)
 {
     if (e.Length != 0)
         progressBar1.Value = (int)(e.BytesRead * 100 / e.Length);
 }
Esempio n. 2
0
        private void UploadButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                // get some info about the input file
                FileInfo fileInfo = new FileInfo(FileTextBox.Text);

                // show start message
                LogText("Starting uploading " + fileInfo.Name);
                LogText("Size : " + fileInfo.Length);

                // open input stream
                using (FileStream stream = new FileStream(FileTextBox.Text, FileMode.Open, FileAccess.Read))
                {
                    using (StreamWithProgress uploadStreamWithProgress = new StreamWithProgress(stream))
                    {
                        uploadStreamWithProgress.ProgressChanged += uploadStreamWithProgress_ProgressChanged;

                        // start service client
                        TerriFileTransferServiceClient terri = new TerriFileTransferServiceClient();

                        // upload file
                        terri.UploadFile(fileInfo.Name, fileInfo.Length, _getuser, uploadStreamWithProgress);

                        LogText("Done!");
                        listBox1.Items.Clear();
                        getContents();
                        // close service client
                        terri.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogText("Exception : " + ex.Message);
                if (ex.InnerException != null) LogText("Inner Exception : " + ex.InnerException.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }