Beispiel #1
0
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            string fileName = SelectFile();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            FileStream     stream  = File.OpenRead(fileName);
            IUpLoadService service = new UpLoadServiceClient();
            var            req     = new FileUploadMessage(fileName.Substring(0, fileName.LastIndexOf('.')), "", stream);

            service.UploadFile(req);
            stream.Close();
            this.Cursor = Cursors.Default;
            MessageBox.Show("文件上传到服务器成功", "上传WCF", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #2
0
        private void btnDownLoad1_Click(object sender, EventArgs e)
        {
            string fileName = SelectFile();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            DownFileRequest req = new DownFileRequest(fileName);
            IUpLoadService  svc = new UpLoadServiceClient();
            var             res = svc.DownLoadFile(req);

            if (res.IsSuccess)
            {
                using (var fileStream = File.Create(AppDomain.CurrentDomain.BaseDirectory + "\\" + fileName.Substring(fileName.LastIndexOf('\\') + 1)))
                {
                    CopyTo(res.FileStream, fileStream);
                }
            }
            this.Cursor = Cursors.Default;
            MessageBox.Show(res.IsSuccess?"文件下载成功!":res.Message, "上传文件测试", MessageBoxButtons.OK,
                            res.IsSuccess ? MessageBoxIcon.Information : MessageBoxIcon.Error);
        }