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

Notifications

Announcements

No record found.

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,883
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)
  • Suggested answer
    Anthony Blake Profile Picture
    2,963 Super User 2025 Season 2 on at
    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.
     
  • Anthony Blake Profile Picture
    2,963 Super User 2025 Season 2 on at
  • Faqruddin Profile Picture
    1,883 on at
    Thank you for your responses. Please any X++ code examples to write to cloud storage?
  • Anthony Blake Profile Picture
    2,963 Super User 2025 Season 2 on at
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,431 Super User 2025 Season 2 on at
     
    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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans