permission denied execption
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: permission denied execption

  1. #1
    Join Date
    May 2011
    Posts
    3

    Question 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

  2. #2
    Join Date
    May 2011
    Posts
    3

    Re: permission denied execption

    i am using framework 4.0

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,985

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    May 2011
    Posts
    3

    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.

  5. #5
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center