Copy Files From Winform App to Directory RRS feed

  • Question

  • I'm trying to build a installer for an app I made. I'm trying to copy files from installer app to a directory. Getting a file access denied error. I'm using Admin account. 


     //Remove Files & Folders
                        if (Directory.Exists(_AppData.InstallPath)) { Directory.Delete(_AppData.InstallPath); }
                        //Install Fresh Copy
                        string GameDirectory = Environment.CurrentDirectory + @"\Game";

    private void Copy(string sourceDir, string targetDir)
                foreach (var file in Directory.GetFiles(sourceDir))
                    File.Copy(file, Path.Combine(targetDir, Path.GetFileName(file)));
                foreach (var directory in Directory.GetDirectories(sourceDir))
                    Copy(directory, Path.Combine(targetDir, Path.GetFileName(directory)));
                pbInstall.Visible = false;

    Monday, May 18, 2020 3:54 AM

All replies

  • Hi old_School,

    Thank you for posting here.

    Although the account you are using now has administrator permission, this does not mean that the programs you develop have that.

    If you run your program as "Run as administrator", this error will not appear.

    If possible, we'd better not store the application data in "C: \ Program Files (x86) ".

    It is an option to store the data in "C: \ Users \ <username> \ AppData" in the following way.

    Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData)

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 28, 2020 8:16 AM