Moving files programatically
-
Hi there, I hope someone can help me regarding a windows form program. I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me? I hope I have explained this clearly enough. Thanks, F
-
Hi there, I hope someone can help me regarding a windows form program. I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me? I hope I have explained this clearly enough. Thanks, F
Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);
-
Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);
-
Thanks for your answer. I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file? Thanks again for your help. F
When you retrieve the FileName from either the OpenFileDialog or the SaveFileDialog, it should contain both the path and file name, I believe.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: How 'bout a little guitar now? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango