Robbie  Hoskins
Robbie Hoskins

Reputation: 11

FileSystem.CopyFile throws "File not found" even if the file is present

I thought this would be simple but it obviously isn't...

I'm trying to copy a file in the AppData folder - specifically the templates folder:

Dim path As String
path = Environment.GetFolderPath(Environment.SpecialFolder.templates)
path = path & "\Normal.dotm"

My.Computer.FileSystem.CopyFile(path, "c:\test\normal.dotm", True)

The code above throws the following error:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.VisualBasic.dll

Additional information: Could not find file 'C:\Users\EAZIE\AppData\Roaming\Microsoft\Windows\Templates\Normal.dotm'.

I know the file is there as I can move it manually. I can run the code on other files perfectly fine.

I've also tried running the program with administrative rights.

Upvotes: 0

Views: 552

Answers (1)

Robbie  Hoskins
Robbie Hoskins

Reputation: 11

thanks guys for pointing this out the Environment.SpecialFolder.Templates did not point to the folder i thought at first

Are you sure the file is in that folder and not C:\Users\EAZIE\AppData\Roaming\Microsoft\Templates? Note the extra "Windows" in your path. – Mark

To confirm Mark's suggestion, Environment.SpecialFolder.Templates points to users\name\appdata\roaming\Microsoft\windows\templates while the Normal.dotm file is found in users\name\appdata\roaming\Microsoft\templates – Dalton D

Upvotes: 1

Related Questions