c# - Receiving UnauthorizedAccessException When Trying to Move File -


i'm writing regression tests , need manually move file 1 location another. each time unauthorizedaccessexception happens, i'm assuming has permissions of folder file has moved from? i've checked file attributes , not set read-only. other questions , answers, i've tried setting attribute within program normal. i've thought maybe using setaccesscontrol help, i'm having trouble figuring out how set filesecurity parameter. of course, way off on issue well. in terms of permissions, administrator on local machine , on network, , if try moving files , locations in question powershell, no issues, don't have elevate or force, visual studio running on different permissions, , if so, how can change that? here code:

    internal static bool process5010claims(string batch)     {         string batchregex = createbatchregex(batch);         string batchonfilesystem = adddecimaltobatch(batch);         bool isfound = false;         string pth = @"\\hedgefrog\root\uploads";         string destination = @"\\apexdata\data\claimstaker\claims\auto\5010";         string[] files = directory.getfiles(pth);         foreach (var file in files)         {             if (regex.ismatch(file, batchregex))             {                 string fullpath = path.combine(pth, batchonfilesystem);                 var attr = new fileinfo(fullpath);                   //                 try                 {                     file.move(fullpath, destination);                     isfound = true;                     break;                 }                 catch (filenotfoundexception)                 {//already been moved new directory                 }                 catch (unauthorizedaccessexception e)                 {                     //in middle of being moved?                 }                 catch (ioexception)                 {                 }//already been moved new directory             }         } 

the exception isn't giving me real information, i'm getting is: unauthorizedaccessexception caught acces path denied

it appear aren't specifying name of file when doing move.

try changing code this:

if (regex.ismatch(file, batchregex))         {             var fullpath = path.combine(pth, batchonfilesystem);             var fulldestinationpath = path.combine(destination, batchonfilesystem);             var attr = new fileinfo(fullpath);             try             {                 file.move(fullpath, fulldestinationpath);                 isfound = true;                 break;             } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -