Example #1
0
 private void DownloadButton_Click(object sender, RoutedEventArgs e)
 {
     if (DocumentHistory.SelectedIndex != -1)
     {
         if (history[DocumentHistory.SelectedIndex].id != -1)
         {
             int            index          = history[DocumentHistory.SelectedIndex].id;
             string         fileName       = DatabaseHandler.GetDocumentHistoryFileName(index);
             string         fileType       = fileName.Substring(fileName.LastIndexOf("."));
             SaveFileDialog saveFileDialog = new SaveFileDialog();
             saveFileDialog.InitialDirectory = "c:\\";
             saveFileDialog.FileName         = fileName;
             saveFileDialog.RestoreDirectory = true;
             if (saveFileDialog.ShowDialog() == true)
             {
                 string filePath = saveFileDialog.FileName;
                 if (filePath.EndsWith(fileType))
                 {
                     filePath = filePath.Substring(0, filePath.Length - fileType.Length);
                 }
                 if (filePath.Length > 260 - fileType.Length)
                 {
                     filePath = filePath.Substring(0, 260 - fileType.Length);
                 }
                 filePath += fileType;
                 DatabaseHandler.DownloadDocument(index, filePath);
                 System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{filePath}\"");
             }
         }
         else
         {
             System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{docHistoryChanges[docHistoryChanges.Count - DocumentHistory.SelectedIndex -1].newDocument}\"");
         }
     }
 }