This is the part that crashes and gives me this error is when I try to copy a file to a certain location.
string startupDirectory = \"C:\\\\Users\\\\Tyler\\\
Try this:
File.Copy(startupDirectory, "Startup.exe", true);
File.SetAttributes("Startup.exe", FileAttributes.Normal);
You can run Visual Studio with Administrative Rights. (Assuming Windows7, Right-click on Visual Studio icon in the start menu and click "Run as Administrator")
Try
public static void Copy(string sourceFileName, string destFileName);
First overload is source 2nd overload is destination i think reason might be this
File.Copy("Startup.exe",startupDirectory);
Try setting the access permissions to "Full control" for the .Net user from where you are reading/saving the files.
For Access Denied Error in IIS server for particular file , please follow the below steps
1- Goto to C:\\Users\\Tyler\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup
2- Right click on your file -> Properties -> Pop Up of User properties appears -> click on Security tab-> click on Edit -> select Users-> tick on Allow Full Control -> Click Ok
This will surely solve the Access denied problem
An UnauthorizedAccessException means one of 3 things:
This exception is triggered by a Windows error. It does not have a dedicated "this make absolutely no sense" error code, it just produces an "access denied" error code. Which .NET translates to a UnauthorizedAccessException.
The "makes no sense" problem here is that you are trying to copy a directory with a file copy method. Directories are not files. Copying a directory requires creating a new directory first, then copying all of the files in the directory. .NET has a method for that, most C# programmers tend to think it is the 'wrong' namespace. It is Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory().
But you'll need to think a bit more about this problem, it of course doesn't make sense to call the new directory "startup.exe". A probably meant to copy a specific file from the Startup directory, we can't guess what it might be.