permission denied execption
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.
please help me with this. Thanks in Advance
Re: permission denied execption
Re: permission denied execption
Look at this code:
using System;
using System.IO;
Code:
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"));
}
}
http://www.dotnetperls.com/file-copy
Re: permission denied execption
thanks dglienna for the reply ....
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.
Re: permission denied execption
Hrm? I don't understand the objection to dglienna's solution. File.Copy is a file-type-agnostic copy method. That is:
Code:
File.Copy("file-a.txt", "file-b.txt", true); // overwrite = true
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?)