0

I am using file.copy() method to copy a file from source directory to destination directory in my vb.net windows application. and I am getting below error:

Access to path '\sample\windows\path' is denied.

Try
   If File.Exists(sourcepath) Then
      File.SetAttributes(sourcepath, FileAttributes.Normal)
   End If
   If Not Directory.Exists(dest) Then
      Directory.CreateDirectory(dest)
   End If

   File.Copy(sourcePath, destPath, True)
Catch ex As Exception
   System.Windows.MessageBox.Show(ex.Message)
End Try

Although I am able to access the specified windows path.I am running application with administrator privileges still i am getting this error.What can be the reason for this error.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Laxmi
  • 13
  • 4
  • Update your question with your code please. Also I don't like to assume so will ask, is **'\sample\windows\path'** the full path that your application is trying to copy to as that isn't a valid file path. – Bugs Oct 25 '16 at 10:14
  • Have a look at [this](http://stackoverflow.com/questions/8821410/why-is-access-to-the-path-denied) – Bugs Oct 25 '16 at 11:03
  • @Jinx88909 I tried every solution listed there. like giving full permissions to that folder, sleep statements, running as administrator etc. but nothing worked for me..:( – Laxmi Oct 25 '16 at 11:08
  • It could be the file attributes rather than the file permissions. Would be better to have a look at your code too if possible – Bugs Oct 25 '16 at 11:09
  • @Jinx88909 sure, i have edited the question with code.. – Laxmi Oct 25 '16 at 11:29
  • OK thanks. Does the file already exist and it's trying to overwrite it? – Bugs Oct 25 '16 at 11:34
  • no file doesn't exist there in destination. – Laxmi Oct 25 '16 at 11:41
  • The code looks OK to be fair so it will be something on the directory you are trying to copy too. Can you manually create a file in the directory as yourself or as administrator. Is this **sit_test** folder shared out? Just trying to understand the structure you have set up. – Bugs Oct 25 '16 at 11:50
  • You can use the Effective Permissions dialogue within Windows to check the permissions on an object for a specific username. This could show whether the account you are making the connection with has appropriate rights to delete. See this [technet](https://technet.microsoft.com/en-us/library/cc771586(v=ws.11).aspx) article for details – G Davison Oct 25 '16 at 12:08
  • @Jinx88909 Yes it is a shared folder and i am able to copy the same file from source to destination manually.. not getting what it is prompting error even after having proper access. – Laxmi Oct 25 '16 at 13:26

0 Answers0