-
May 7th, 2011, 04:45 AM
#1
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
-
May 7th, 2011, 04:47 AM
#2
Re: permission denied execption
-
May 7th, 2011, 01:26 PM
#3
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
-
May 7th, 2011, 01:34 PM
#4
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.
-
May 7th, 2011, 03:32 PM
#5
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?)
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|