//public string status { get; set; } public void Execute(object parameter) { _canExecute = false; // status = "sending"; byte[] b; var dialog = new OpenFileDialog(); dialog.Multiselect = false; var flvm = (FolderListVM)parameter; if (string.IsNullOrEmpty(flvm.SelectedFolder)) { MessageBox.Show("Please select a folder."); return; } bool? fileselected = dialog.ShowDialog(); if (fileselected.HasValue && fileselected.Value) { var fileinfo = dialog.File; using (FileStream reader = fileinfo.OpenRead()) { var fs = new FileServiceClient(); b = new byte[fileinfo.Length]; reader.Read(b, 0, (int)fileinfo.Length); string fileName = fileinfo.Name; fs.SendFileCompleted += (sender, args) => { var res = (string) args.Result; if (res != "success") { MessageBox.Show("Error uploading: " + res); } else { flvm.CommandListFiles.Execute(flvm); } }; try { string filepath = Path.Combine(flvm.ClientRepository, flvm.SelectedFolder) + "\\" + fileName; fs.CheckFileExistsCompleted += (sender, args) => { var Exists = (bool)args.Result; if (!Exists) { fs.SendFileAsync(b, filepath); } else { var resu = MessageBox.Show("File already exists, would you like to replace?", "FileExists", MessageBoxButton.OKCancel); if (resu == MessageBoxResult.OK) { fs.SendFileAsync(b, filepath); } } }; fs.CheckFileExistsAsync(filepath); } catch (Exception ex) { MessageBox.Show(ex.Message); } // status = filebytes; } } _canExecute = true; }