public void DownloadElement(FileInDB selectedFile) { saveFileDialog.FileName = selectedFile.FileName; if (saveFileDialog.ShowDialog() == true) { File.WriteAllText(saveFileDialog.FileName, Encoding.UTF8.GetString(SevenZipHelper.Decompress(selectedFile.BinaryData))); } }
public void PushFileToServer() { if (openFileDialog.ShowDialog() == true) { switch (RenameDialog()) { case MessageBoxResult.Yes: { FileNameDialog dialog = new FileNameDialog(new FileNameDialogM(GetCompressedFileInByteArray()), Path.GetFileNameWithoutExtension(openFileDialog.FileName)); dialog.Show(); } break; case MessageBoxResult.No: UploadFile(); break; } } void UploadFile() { Task.Run(() => sql.UploadFile(Path.GetFileNameWithoutExtension(openFileDialog.FileName), GetCompressedFileInByteArray())); } MessageBoxResult RenameDialog() { return(MessageBox.Show(messageBoxText, caption, button, icon)); } Byte[] GetCompressedFileInByteArray() { using (streamReader = new StreamReader(openFileDialog.FileName, System.Text.Encoding.GetEncoding(1251))) { using (binaryReader = new BinaryReader(streamReader.BaseStream)) { return(SevenZipHelper.Compress(binaryReader.ReadBytes((int)streamReader.BaseStream.Length))); } } } }