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, ...
Suggested Answer

Error While Accessing a shared folder using x++

(0) ShareShare
ReportReport
Posted on by 25

System.IO.IOException: The user name or password is incorrect.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption)
at Dynamics.Ax.Application.Loopdirectory() in a.xpp:line 22
at Dynamics.Ax.Application.Run() in a.run.xpp:line 6
at Dynamics.Ax.Application.BatchRun.runJobStaticCode(Int64 batchId) in BatchRun.runJobStaticCode.xpp:line 54
at Dynamics.Ax.Application.BatchRun.runJobStatic(Int64 batchId) in BatchRun.runJobStatic.xpp:line 13
at BatchRun::runJobStatic(Object[] )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
at BatchIL.taskThreadEntry(Object threadArg)

Running a job in batch job i am getting this error 

directory = new System.IO.DirectoryInfo(@"XXXXXX");
files = directory.GetFiles();
filesCount = files.get_Length();

I have the same question (0)
  • Axbeginerss Profile Picture
    25 on at

    directory = new System.IO.DirectoryInfo(@"XXXXXX");

    files = directory.GetFiles();

    getting the error at files = directory.GetFiles();

    but every time i am accessing the file using Wind+R  it is asking username and password. how to pass username and password through code. ??

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Your question is about a .NET API, it doesn't seem specific to Dynamics AX, therefore you should look at .NET resources rather then AX resources. This even isn't the best forum.

    Look at C#: How to logon to a share when using DirectoryInfo (at StackOverflow), for example.

    Nevertheless a better approach would be putting the file somewhere where it can be read. If you run your code on server, it's the AOS service account that needs permissions.

  • Axbeginerss Profile Picture
    25 on at

    System.IO.DirectoryInfo     directory;

       System.IO.FileInfo[]        files;

       System.IO.FileInfo          file;

       InteropPermission           permission;

       Filename                    tmpFilePath;

       Filename                    tmpFileNameShort;

       Filename                    tmpFileExt;

       str         fileNameTemp;

       counter     filesCount;

       counter     loop;

       permission  = new InteropPermission(InteropKind::ClrInterop);

       permission.assert();

       directory   = new System.IO.DirectoryInfo(@"");

       files       = directory.GetFiles();

       filesCount  = files.get_Length();

       for (loop = 0; loop < filesCount; loop++)

       {

           file                                        = files.GetValue(loop);

           fileNameTemp                                = file.get_FullName();

           [tmpFilePath, tmpFileNameShort, tmpFileExt] = fileNameSplit(fileNameTemp);

           this.importExcel(tmpFileNameShort);

       }

       CodeAccessPermission::revertAssert();

    i am using in Ax only. Martin !!

  • Axbeginerss Profile Picture
    25 on at

    It is working fine when we run the batch job manually

    but when running in batch it is throwing the above error.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You're not using AX only. System.IO.DirectoryInfo class is defined in .NET Framework (see documentation). That you're using interoperability with something else and not just AX is also obvious from InteropPermission.

    By the way, please use Insert > Insert Code (int the rich-formatting view) to paste source code. It makes code easier to read and work with.

  • Suggested answer
    Fangyuan Hou Profile Picture
    on at

    Hi Axbeginerss,

    You are saying that It is working fine when we run the batch job manually, are you implement this code in a class which extends RunBaseBatch? Which user is run the batch job?

    If yes, have you implement runsImpersonated method to return true?

    docs.microsoft.com/.../batch-processing-classes

    If still not working, maybe can you try to add below line before GetFiles() to see whether it works?

    #File

    new FileIOPermission(folder, #io_read).assert();

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 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans