private async void OpenFileDialog() { if (SelectedUser == null) { return; } var dialog = new OpenFileDialog(); if (dialog.ShowDialog() == true) { if (Message.Attachments == null) { Message.Attachments = new ObservableCollection <Attachment>(); } //todo multiselect var pathItems = dialog.FileName.Split('\\'); var attachment = new Attachment { Document = new Document { FullName = pathItems.Last() }, Type = "doc", Path = string.Join("//", pathItems.Take(pathItems.Length - 2)) //отрезали имя файла }; Message.Attachments.Add(attachment); OnPropertyChanged("Message"); var fileNameHash = _cryptTool.CreateHash(dialog.FileName) + ".txt"; var key = _cryptTool.EncryptFile(dialog.FileName, fileNameHash); var uploadedFile = await UploadFile(fileNameHash, SelectedUser.Id, attachment); File.Delete(fileNameHash); if (uploadedFile == null) { Message.Attachments.Remove(attachment); return; } attachment.Document.Id = uploadedFile.Id; attachment.Document.OwnerId = uploadedFile.OwnerId; attachment.Document.Url = uploadedFile.Url; attachment.Document.FileName = uploadedFile.FileName; attachment.EncryptedSymmetricKey = key; } }