Esempio n. 1
0
        /// <summary>
        ///     选择文件对话框事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectFilesButton_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog {Multiselect = true};

            try
            {
                if (!string.IsNullOrEmpty(_fileFilter))
                    ofd.Filter = _fileFilter;
            }
            catch (ArgumentException ex)
            {
                //User supplied a wrong configuration file
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() != true) return;
            foreach (var file in ofd.Files)
            {
                var userFile = new UploadFile
                {
                    FileName = file.Name,
                    FileStream = file.OpenRead()
                };

                if (userFile.FileStream.Length <= _maxFileSize)
                {
                    //向文件列表中添加文件信息
                    _files.Add(userFile);
                }
                else
                {
                    MessageBox.Show( "Maximum file size is: " + (_maxFileSize/1024) + "KB.");
                }
            }
        }
Esempio n. 2
0
        public UploadTools(UploadFile file, string serviceUrl = @"../SilverlightUploadService.svc")
        {
            _file = file;
            if (_file.CancelAction == null)
            {
                file.CancelAction += CancelUpload;
            }
            _file.BytesUploaded = 0;

            _client = new SilverlightUploadServiceClient();
            _client.Endpoint.Address = new EndpointAddress(serviceUrl);
            _client.StoreFileAdvancedCompleted += _client_StoreFileAdvancedCompleted;
            _client.CancelUploadCompleted += client_CancelUploadCompleted;
            _client.ChannelFactory.Closed += ChannelFactory_Closed;
        }