Przeglądaj źródła

Catching and ignoring exception when outlook keeps files open in document window

Kenric Nugteren 1 rok temu
rodzic
commit
75be707008
1 zmienionych plików z 8 dodań i 1 usunięć
  1. 8 1
      inabox.wpf/DynamicGrid/DynamicDocumentGrid.cs

+ 8 - 1
inabox.wpf/DynamicGrid/DynamicDocumentGrid.cs

@@ -295,7 +295,14 @@ namespace InABox.DynamicGrid
                     Task.Run(() =>
                     {
                         var tempfile = Path.Combine(System.IO.Path.GetTempPath(), SanitiseFileName(file.Key));
-                        File.WriteAllBytes(tempfile, file.Value);
+                        try
+                        {
+                            File.WriteAllBytes(tempfile, file.Value);
+                        }
+                        catch
+                        {
+                            // Outlook likes to keep files open apparently, which breaks this code.
+                        }
                         var info = new System.Diagnostics.ProcessStartInfo(tempfile);
                         info.UseShellExecute = true;
                         info.Verb = "Open";