0

I am working with a client application that needs to have a local repository to save updates made to a group of objects, called "Books". However, I am not able to save the objects back into the SQL server until the entire book has been updated. So the powers that be have decided to use an excel file as a repository, we are calling a work list.

The user has to be able to name the work list so that it is meaningful to them, but they cannot be able to edit the work list in excel. My idea was to create a hidden folder to store the work lists, and the app can retrieve them from that location.

Here is my question: Is there a way to keep the windows dialog box hidden, so the user cannot choose where the file is saved to, yet pass a name to the dialog for the work list?

I am using the standard Microsoft.Win32.SaveFileDialog currently, but I can change, if I need to, in order to accomplish this task.

Here is my SaveFileDialog code, that allows the user to change the name but also the path to where the file saves:

 public void SaveToFile(string BookName)
    {

        var file = "";
        Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
        dlg.FileName = string.Format("{0} \\{1} Codes", WORKLIST_SAVE_PATH, BookName); // Default file name
        dlg.DefaultExt = ".xlsx"; // Default file extension
        dlg.Filter = " Excel Files (.xlsx)|*.xlsx"; // Filter files by extension
        Nullable<bool> result = dlg.ShowDialog();
        if (result == true)
        {
            // Save document
            file = dlg.FileName;
        }
        else return;
        File.WriteAllText(file, Export(true));
    }
tCoe
  • 401
  • 1
  • 5
  • 24
  • 8
    Why use a SaveFileDIalog ? Why not create a simple dialog that allows them to specify a file name. – auburg Nov 29 '18 at 16:26
  • not sure how to save without the SaveFileDialog. I am gonna look into that... – tCoe Nov 29 '18 at 17:02
  • 1
    It would help if you posted your code – auburg Nov 29 '18 at 17:04
  • @auburg - I updated to show the current dialog code. Also not finding a way to save without the SaveFileDialog.. any hints on where I should look? – tCoe Nov 29 '18 at 17:11
  • 1
    I take it this is a WPF app ? You can create your own custom dialog that allows the user to enter a filename in a text field and your existing code would use that filename as part of the (secret) path that you're saving to i.e. file = Path.Combine( – auburg Nov 29 '18 at 17:18
  • 1
    See also https://stackoverflow.com/questions/2796470/wpf-create-a-dialog-prompt (assuming WPF - Winforms is even easier) – auburg Nov 29 '18 at 17:21
  • That link was what i was looking for to get me over the hump. thank you. – tCoe Nov 29 '18 at 17:50

0 Answers0