i am writing a code for copy one file from a location to another.
The code is as follows:
Scripting.FileSystemObject copyobj = new Scripting.FileSystemObject();
bool overWrite = true;
copyobj.CopyFile(file, copy_destination, overWrite);
===========================================
when the code gets executed on CopyFile function is throws an execption as follows:
HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)
I am able to copy file from any location to my drives i.e. (c:\ or d:\) but this execption arises if i want to copy files into a folder i.e. c:\foldername or d:\foldername.
class Program
{
static void Main()
{
// Write initial contents of File B.
Console.WriteLine(File.ReadAllText("file-b.txt"));
// "File B contents."
// COPY:
// Copy one file to a location where there is a file.
File.Copy("file-a.txt", "file-b.txt", true); // overwrite = true
// Display the contents of both files
Console.WriteLine(File.ReadAllText("file-a.txt"));
Console.WriteLine(File.ReadAllText("file-b.txt"));
}
}
But my requirement is not only to copy the .txt file and put the contents in .txt file.
It can be any file so thats why i was using that function.
can u help me with the exception.
i have also give the full access to myself on that drive in which i have the folder. still it sayd permission denied.
should work for all file types. Does that code still give you the exception? (Or could you clarify why this won't work in your case?)
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks