web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

System.UnauthorizedAccessException Access to the path is denied

(1) ShareShare
ReportReport
Posted on by 1,881
Dear All,
 
I have a requirement to write a file on local disk C. I use following code but it's failed to create a file and throws error access denied. I granted folder permissions full control but no luck. Please advice further.
 
        str filepath = "";
        Set    permissionSet = new set(types::Class);
        filepath = @"C:\test\test.txt";
        System.Text.Encoding encoding = new System.Text.UTF8Encoding(false); 
        permissionSet.add(new FileIOPermission(filepath, 'rw'));
        permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
        CodeAccessPermission::revertAssert();
        CodeAccessPermission::assertMultiple(permissionSet);
       // WinAPIServer::createFile(filepath); not works same error
        System.IO.File::WriteAllText(filepath, "Data 123", encoding);
        CodeAccessPermission::revertAssert();
        info('done');
 
I have the same question (0)
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,294 Super User 2025 Season 2 on at
    System.UnauthorizedAccessException Access to the path is denied
     
    I think you can use BusinessEvent and power automate to store the file in local disc using on-premises data gateway connector.
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Anthony Blake Profile Picture
    2,617 Super User 2025 Season 2 on at
    System.UnauthorizedAccessException Access to the path is denied
  • Faqruddin Profile Picture
    1,881 on at
    System.UnauthorizedAccessException Access to the path is denied
    Thank you for your responses. Please any X++ code examples to write to cloud storage?
  • Anthony Blake Profile Picture
    2,617 Super User 2025 Season 2 on at
    System.UnauthorizedAccessException Access to the path is denied
  • Suggested answer
    Anthony Blake Profile Picture
    2,617 Super User 2025 Season 2 on at
    System.UnauthorizedAccessException Access to the path is denied
    Hi Faqruddin,
     
    As Finance is a cloud solution, you cannot access your C drive via code.
     
    There are a number of patterns you can explore instead, you could present the file to the user for download in the browser when ready, or write it to cloud storage.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 756 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 629 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 514 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans