From 94721c4273d5cec73fff9339f2fd969430ea1320 Mon Sep 17 00:00:00 2001 From: Andrew Lesh Date: Tue, 23 Jan 2024 15:27:52 -0500 Subject: [PATCH] Make extracting attachments optional when the folder text box hasn't been filled. MessageBox now alerts user that extraction will continue unless they hit cancel. --- NSF2SQL/Form1.cs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/NSF2SQL/Form1.cs b/NSF2SQL/Form1.cs index 00961f8..ff949fa 100644 --- a/NSF2SQL/Form1.cs +++ b/NSF2SQL/Form1.cs @@ -326,11 +326,16 @@ private void bExportDocuments_Click(object sender, EventArgs ea) MessageBox.Show("Select a database."); return; } - if (string.IsNullOrEmpty(txbAttachmentsFolder.Text)) + + string attachmentsFolder = txbAttachmentsFolder.Text; + + if (string.IsNullOrEmpty(attachmentsFolder)) { - MessageBox.Show("Select a folder for attachments."); - return; + var result = MessageBox.Show("You did not select a destination for attachments. The export will proceed without pulling any of those fields. Cancel to select a folder.", "Notice", buttons: MessageBoxButtons.OKCancel); + + if (result == DialogResult.Cancel) return; } + int total = 0; long startTicks = 0; long lastTicks = 0; @@ -367,19 +372,21 @@ private void bExportDocuments_Click(object sender, EventArgs ea) for (int i = 0; i < total; i++) { object[] items = (object[])doc.Items; - - foreach (NotesItem nItem in items) + if (!string.IsNullOrWhiteSpace(attachmentsFolder)) { - if (nItem.Name == "$FILE") + foreach (NotesItem nItem in items) { - NotesItem file = doc.GetFirstItem("$File"); + if (nItem.Name == "$FILE") + { + NotesItem file = doc.GetFirstItem("$File"); - string fileName = ((object[])nItem.Values)[0].ToString(); + string fileName = ((object[])nItem.Values)[0].ToString(); - NotesEmbeddedObject attachfile = doc.GetAttachment(fileName); + NotesEmbeddedObject attachfile = doc.GetAttachment(fileName); - if (attachfile != null) - attachfile.ExtractFile($@"{txbAttachmentsFolder.Text}\{fileName}"); + if (attachfile != null) + attachfile.ExtractFile($@"{attachmentsFolder}\{fileName}"); + } } } @@ -393,7 +400,7 @@ private void bExportDocuments_Click(object sender, EventArgs ea) { //get form string form = ((string[])doc.GetItemValue("Form"))[0]; - + if (!tables.ContainsKey(form)) { tables.Add(form, new Table(form)); @@ -856,7 +863,7 @@ private NotesSession initSession(string password) private void btnBrowseAttachmentsFolder_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) - txbAttachmentsFolder.Text = folderBrowserDialog1.SelectedPath; + txbAttachmentsFolder.Text = folderBrowserDialog1.SelectedPath; } } }