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();
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();
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.
It is working fine when we run the batch job manually
but when running in batch it is throwing the above error.
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 !!
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.
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. ??
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156