I can't copy pdf files downloaded from the internet.
I've even set the File Attributes to normal based on a quick search, but that doesn't work.
All the paths and directories have full access and other types of files can be copied.
Code:
using System;
using System.IO;
namespace Test_Console_App
{
class Program
{
static void Main(string[] args)
{
try
{
var permission = new FileIOPermission(FileIOPermissionAccess.Write, @"D:\dummy.pdf"); // Alternatives tried D:\, E:\ E:\dummy.pdf
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
File.SetAttributes(@"D:\dummy.pdf", FileAttributes.Normal);
if (File.Exists(@"E:\dummy.pdf"))
{
File.Delete(@"E:\dummy.pdf");
}
File.Copy(@"D:\dummy.pdf", @"E:\dummy.pdf", true);
File.SetAttributes(@"E:\dummy.pdf", FileAttributes.Normal);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey();
}
}
}
Error:
System.UnauthorizedAccessException: Access to the path 'E:\dummy.pdf' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at Test_Console_App.Program.Main(String[] args) in D:\Projects\Test_Console_App\Test_Console_App\Program.cs:line 26