Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am needing the ability to prompt the user to save all the files that have just been created by the application.

1. Is it possible to prompt saveas boxes sequentially for each file?
2. If not, what would you suggest a good work around would be?

Thank you.

List<string> convertedFiles = new List<string>();
                 string newFile = "";
                 string convertedFileName = "";
                 foreach (var Agencynumber in agencyfile)
                 {
                     convertedFileName = Agencynumber + "-Authorize.Net - " + date1 + " @ " + date2 + ".ach";
                     newFile = "C:\\authorize.netTEST\\" + Agencynumber + "-Authorize.Net - " + date1 + " @ " + date2 + ".ach";
                     //Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), convertedFileName);

                     StreamWriter sw2 = new StreamWriter(newFile, true);
                     foreach (DataRow dr in dt.Rows)
                     {
                         if (dr[12].ToString().Contains(Agencynumber + "|"))
                         {
                             if (dr[0].ToString() != "2")
                             {
                                 if (dr[9].ToString() != "Total Amount")
                                 {
                                     sw2.Write("6                            ");
                                     sw2.Write(dr[9].ToString().Replace(".", "").Replace(",", "").PadLeft(10, '0'));
                                     sw2.Write((dr[12].ToString().Replace(Agencynumber + "|", "")).PadRight(15, ' '));
                                     sw2.Write((dr[13].ToString() + " " + dr[14].ToString()).PadRight(40));
                                     sw2.Write(sw2.NewLine);
                                 }
                             }
                         }
                     }
                     sw2.Write("9");
                     sw2.Write(sw2.NewLine);
                     sw2.Close();
                     convertedFiles.Insert(convertedFiles.Count, newFile);
                }
                 foreach (string newfile in convertedFiles)
                 {
                     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                     saveFileDialog1.Filter = "txt files (*.ach)|*.ach|All files (*.*)|*.*";
                     saveFileDialog1.DefaultExt = "ach";
                     saveFileDialog1.FilterIndex = 2;
                     saveFileDialog1.InitialDirectory = @"C:\";
                     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                     {

                     }
                 }


Ok, I have changed my code a bit and am getting a savefiledialog for each file created. However, there is no file in the "File name" field of the savefiledialog. How do I get my created files into the field so they can be saved?
Posted
Updated 3-Jul-12 3:46am
v6
Comments
[no name] 28-Jun-12 10:18am    
1. Of course you can. 2. Depends entirely on the structure of the program.
[no name] 3-Jul-12 10:27am    
saveFiledialog1.FileName = newfile;
[no name] 3-Jul-12 10:47am    
Seems to me that you are putting too much work into this. Your "newfile" string already has a path and filename so why do you need the save file dialog? Just save the file and be done with it.
Richard C Bishop 3-Jul-12 11:11am    
I agree, this is taking way too long. I guess I do not know how to save a file without using Save file dialog or response.writefile and response.flush.

The files are being written to a single location, but I need the user to be able to save them where they want to.
[no name] 3-Jul-12 11:37am    
The files already exist right? Popup a folder browse dialog and let the user select the folder to save the files in and then do a File.Move() or something like that for each of the files that you need to move/copy.

Yes, you can prompt the user for the save location of each file you have in the list. They may hate you, but you can do it. One way to do this would be to put the list of files into a foreach loop and put the save dialog inside the loop. Then, you would get a prompt for each file in your list.
 
Share this answer
 
Comments
Richard C Bishop 28-Jun-12 11:00am    
Ok, I did that and I get prompted for for one save box. I will post the code I have.
Richard C Bishop 28-Jun-12 17:20pm    
Do you see a problem with my code on why it only prompts one box?
Tim Corey 28-Jun-12 17:38pm    
I don't see where your code prompts for any box. That might be your problem. If you leave your dialog outside of this foreach loop, it won't be displayed for each file.
Richard C Bishop 28-Jun-12 17:57pm    
It is at the bottom with all the response."" lines. That prompts a save as box with the file that was created.
Tim Corey 28-Jun-12 18:04pm    
I'm not sure how you are generating the Save dialog in this. If you step through the code, look at where the dialog actually pops up. If it were in this loop statement, you would get one for each file. However, I don't think it is popping up there.
A better alternative may be to have the user choose a folder (Folder Browser Dialog)[^] and then save the files using set names.
Your names could be hard coded or configurable through the application or maybe just an external XML.

I think your users whould be much happier.
Also this tends to make more sence in bulk saves as the files are actually tied together so having them all in a folder with consitent naming to a previous save makes sense IMO.
 
Share this answer
 
v2
Comments
Richard C Bishop 28-Jun-12 14:55pm    
I agree, that does sound like a more user friendly method. I have tried to implement it in my application and cannot get it to work. It is basically an entire class and I am not sure how to use it with my application. Any advice on how to get started with that?
[no name] 3-Jul-12 10:39am    
Its really a design question on how you organize things. You are already "prompting" them (or planning on it).
Go to your end users and ask them how they want the data organized. Get some file naming conventions from them (watch them work with what they currently have).
Then just group it all and never prompt them. In fact you can even avoid the FBD for general saves (save to their docs folder or something). Allow them to set the save location in some settings part of your application. That is where you would use the FBD.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900