File.Move no longer working

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
922
Location
Virginia Beach, VA
Programming Experience
10+
@Sheepings makes several good points about error handling (particularly the existing file case).

The point I was trying to make with my post #19 was that I was not getting the exception regarding the file being opened by another process while trying to do a file move. At first I thought it was because of the way the OP was doing his exception and error handling, so I specifically sent breakpoints and enabled first-chance exceptions just in case I was missing something. I never got the file open exception. I would get the file exists exception, but the exception was pretty clear about the the destination existing, rather than the file being open.
 

kriscs1

Member
Joined
Jan 30, 2020
Messages
6
Programming Experience
Beginner
@Sheepings Thanks so much. I'm taking on board what you are saying about error handling. I think because the program will only be run by me on my computer, I didn't handle all the exceptions like I should. Unfortunately though, I still get the same error with your code.

@Skydiver Thank you for checking.

Given that the code works fine for both of you, all I can think of is that it must be something specific to my environment, perhaps as a result of reinstalling Office 365.
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
922
Location
Virginia Beach, VA
Programming Experience
10+
It sounds like you work for a company that has pretty tight locked down systems. Work with you IT security team. Have them isolate a single system and disable the AV for 5 minutes while you do a test run. If it works with AV disabled, and then fails again with AV enabled, have them contact the vendor to try to work with you to debug why.

If AV on or off doesn't make a difference, next work with your desktop image team. See if they will let you setup three VMs that are not actively attached to your work network. In one VM have their current desktop image. In the second, their desktop image from a year ago. In the third, a vanilla installation of Win10 and Office without any of their customizations. Those three different images should help you narrow down where the point of failure is.

As you'll note with my first paragraph above, I'm sort of leaning on the AV software being my prime suspect, but it could also be a bug in the updates sent out by Microsoft. MS has not had a good track record over the past two years with regards to introducing regressions with their patches and updates.
 

kriscs1

Member
Joined
Jan 30, 2020
Messages
6
Programming Experience
Beginner
It sounds like you work for a company that has pretty tight locked down systems. Work with you IT security team. Have them isolate a single system and disable the AV for 5 minutes while you do a test run. If it works with AV disabled, and then fails again with AV enabled, have them contact the vendor to try to work with you to debug why.

If AV on or off doesn't make a difference, next work with your desktop image team. See if they will let you setup three VMs that are not actively attached to your work network. In one VM have their current desktop image. In the second, their desktop image from a year ago. In the third, a vanilla installation of Win10 and Office without any of their customizations. Those three different images should help you narrow down where the point of failure is.

As you'll note with my first paragraph above, I'm sort of leaning on the AV software being my prime suspect, but it could also be a bug in the updates sent out by Microsoft. MS has not had a good track record over the past two years with regards to introducing regressions with their patches and updates.
Thank you. Yeah, I feel like it might be the AV. However, even 30 seconds after the file is supposedly closed, it still won't move.
I went and spoke to someone in IT today and given the nature of the department, I could be waiting a while to get this sorted.

In the meantime, I got around the issue with a not-so-elegent work around.

Instead of:
1) Open each file in the source folder and upload its contents to the table
2) If successful, move the file to the 'Completed' folder

I have created a new folder called 'Processing' and got the following to work:
1) Delete all files in the 'Processing' folder
2) Copy any files from the source folder to the 'Processing' folder
3) Open the files in the 'Processing' folder and upload their contents to the table
4) If successful, move the files from the source folder to the 'Completed' folder

This way, because the files in the source folder aren't actually being opened, File.Move is successful.
The files that are being opened (in the 'Processing' folder) get deleted on the next program run.

Thanks for the help guys.
 

KoenHoof

New member
Joined
Feb 3, 2020
Messages
3
Programming Experience
5-10
Hi Kris,
I got a similar problem trying to delete an excel file, throwing the same exception.
Reinstalling the microsoft database engine did the trick.

Can you try it?
 

kriscs1

Member
Joined
Jan 30, 2020
Messages
6
Programming Experience
Beginner
The Microdoft Access Database Engine?
Hi Kris,
I got a similar problem trying to delete an excel file, throwing the same exception.
Reinstalling the microsoft database engine did the trick.

Can you try it?
Hi KoenHoof,

Unfortunately, I can't verify if that would have fixed the issue as I had to get a complete reimage. However, after the reimage and reinstallation of the database engine, file.move now does work as expected.
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
844
Location
UK
Programming Experience
10+
On a side note; relating to the code I previously posted. When I posted it, I actually focused more on the error of what would happen if the destination file already existed and what to do with it if it did, that I got a little side-tracked and never finished writing out the bit for handing the error of the file being already in-use. Thanks @Skydiver for pointing that out to me off the board, I still haven't had time to edit it, but its nice to see that you guys resolved it buy blaming Microsoft on creating yet another bug which you's resolved yourselves. (y)
 
Top Bottom