Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 37017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:29:04+00:00 2026-05-10T14:29:04+00:00

While creating a file synchronization program in C# I tried to make a method

  • 0

While creating a file synchronization program in C# I tried to make a method copy in LocalFileItem class that uses System.IO.File.Copy(destination.Path, Path, true) method where Path is a string.
After executing this code with destination. Path = 'C:\\Test2' and this.Path = 'C:\\Test\\F1.txt' I get an exception saying that I do not have the required file permissions to do this operation on C:\Test, but C:\Test is owned by myself (the current user).
Does anybody knows what is going on, or how to get around this?

Here is the original code complete.

using System; using System.Collections.Generic; using System.Text; using System.IO;  namespace Diones.Util.IO {     /// <summary>     /// An object representation of a file or directory.     /// </summary>     public abstract class FileItem : IComparable      {         protected String path;         public String Path         {             set { this.path = value; }             get { return this.path; }         }         protected bool isDirectory;         public bool IsDirectory         {             set { this.isDirectory = value; }             get { return this.isDirectory; }         }         /// <summary>         ///  Delete this fileItem.         /// </summary>         public abstract void delete();         /// <summary>         ///  Delete this directory and all of its elements.         /// </summary>         protected abstract void deleteRecursive();         /// <summary>         ///  Copy this fileItem to the destination directory.         /// </summary>         public abstract void copy(FileItem fileD);         /// <summary>         ///  Copy this directory and all of its elements         /// to the destination directory.         /// </summary>         protected abstract void copyRecursive(FileItem fileD);         /// <summary>         /// Creates a FileItem from a string path.         /// </summary>         /// <param name='path'></param>         public FileItem(String path)         {             Path = path;             if (path.EndsWith('\\') || path.EndsWith('/')) IsDirectory = true;             else IsDirectory = false;         }         /// <summary>         /// Creates a FileItem from a FileSource directory.         /// </summary>         /// <param name='directory'></param>         public FileItem(FileSource directory)         {             Path = directory.Path;         }         public override String ToString()         {             return Path;         }         public abstract int CompareTo(object b);     }     /// <summary>     /// A file or directory on the hard disk     /// </summary>     public class LocalFileItem : FileItem     {         public override void delete()         {             if (!IsDirectory) File.Delete(this.Path);             else deleteRecursive();         }         protected override void deleteRecursive()         {             Directory.Delete(Path, true);         }         public override void copy(FileItem destination)         {             if (!IsDirectory) File.Copy(destination.Path, Path, true);             else copyRecursive(destination);         }         protected override void copyRecursive(FileItem destination)         {             Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(                 Path, destination.Path, true);         }         /// <summary>         /// Create's a LocalFileItem from a string path         /// </summary>         /// <param name='path'></param>         public LocalFileItem(String path)             : base(path)         {         }         /// <summary>         /// Creates a LocalFileItem from a FileSource path         /// </summary>         /// <param name='path'></param>         public LocalFileItem(FileSource path)             : base(path)         {         }         public override int CompareTo(object obj)         {             if (obj is FileItem)             {                 FileItem fi = (FileItem)obj;                 if (File.GetCreationTime(this.Path).CompareTo                     (File.GetCreationTime(fi.Path)) > 0) return 1;                 else if (File.GetCreationTime(this.Path).CompareTo                     (File.GetCreationTime(fi.Path)) < 0) return -1;                 else                 {                     if (File.GetLastWriteTime(this.Path).CompareTo                         (File.GetLastWriteTime(fi.Path)) < 0) return -1;                     else if (File.GetLastWriteTime(this.Path).CompareTo                         (File.GetLastWriteTime(fi.Path)) > 0) return 1;                     else return 0;                 }             }             else                 throw new ArgumentException('obj isn't a FileItem');         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:29:05+00:00Added an answer on May 10, 2026 at 2:29 pm

    It seems you have misplaced the parameters in File.Copy(), it should be File.Copy(string source, string destination).

    Also is ‘C:\Test2’ a directory? You can’t copy file to a directory. Use something like that instead:

     File.Copy(      sourceFile,     Path.Combine(destinationDir,Path.GetFileName(sourceFile))     )

    ;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

What is your real world experience with the Microsoft Application Blocks and other Microsoft
I'm creating a file-browser in ASP.Net but I have run into a problem which
I have a legacy VB6 application that uploads file attachments to a database BLOB
I want to merge two branches that have been separated for a while and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.