Kevin
Kevin

Reputation: 25

File.Move Progress bar

I have a program that users are using that will take a file from their system and move it to a network drive in order to be processed and stored. The move itself works fine and everything works properly, unless they are moving a big file and for some reason close the program early and stop the process.

The code I use to move the file is

try { File.Move(docFilepath, docFilePathTo); }
catch (Exception ex)
{
    docName = config.autoRename(docName + docExt.ToUpper()).Split('.')[0];
    File.Move(docFilepath, frmMain.Scans2LF + docName + docExt.ToUpper());
}

Again this works fine. I was wondering if there was a possibility to have a progress bar to display to the user when their file was actually fully in the new location.

I have looked up a couple questions that have a semi relevance to this but not any answer that would work for my situation. Changing the system for moving the file is not an option for me so i am stuck trying to find a way for progress or completion to be finished.

Edit

I can possibly look into changing the way files are moved, main problem would be explaining it so that my boss wouldn't think its a bad idea to change things that work (if people don't close the program.....)

End Edit

I thought of using a look-up for the new file in its location and the size is is currently at as a progress meter but not sure if this would work.

Thanks for any input!

Upvotes: 0

Views: 1756

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43596

If you want to use the Windows file progress dialog just add Microsoft.VisualBasic as a reference and use the FileMove from there

Microsoft.VisualBasic.FileIO.FileSystem.MoveFile("sorceFile.ext", "destFile.ext", Microsoft.VisualBasic.FileIO.UIOption.AllDialogs); 

This will show the same dialog as widnows does, including Cancel options etc if required.

Upvotes: 3

Related Questions