I am reading in a csv file then moving it to folder once read.
I started with the WINApi but when I moved the process to runasbatch I got the usual error.
Now I have this code :-
container fileList;
System.Array dirList;
Filename fileName;
Filename newFileName;
Filename baseFileName;
filePath path;
Filename extension;
int ix;
new InteropPermission(InteropKind::ClrInterop).assert();
dirList = System.IO.Directory::GetFiles( #fromFolder,"*.csv" );
for( ix=0; ix < ClrInterop::getAnyTypeForObject( dirList.get_Length() ); ix++ )
{
Filename = ClrInterop::getAnyTypeForObject( dirList.GetValue(ix));
[path, baseFileName, extension] = Global::fileNameSplit(fileName);
if(this.importFile(Filename))
{
newFileName = #processedFolder+"\\"+baseFileName+"_"+strrem(date2str(today(), 321,2,2,2,2,4,2),".")+"_"+strreplace(time2str(timenow(),3,3)," ","")+extension;
}
else
{
newFileName = #ErrorFolder+"\\"+baseFileName+"_"+strrem(date2str(today(), 321,2,2,2,2,4,2),".")+"_"+strreplace(time2str(timenow(),3,3)," ","")+extension;
}
//clear CommaIO from "ImportFile()"
importFile = null;
System.IO.File::Copy(Filename, newFileName, true);
new InteropPermission(InteropKind::ClrInterop).assert();
System.IO.File::Delete(filename);
}
Which works great when I run it directly, however when I run it on the batch it gives me an error (detailed at the end of this post)
System.IO.IOException: The process cannot access the file '\\myserver\files\export.csv' because it is being used by another process.
Which is strange because the folder permissions are set to "everyone" full control, and when I run the process off the AOT its find and works.
Any ideas?
Full error :-
System.IO.IOException: The process cannot access the file '\\abvsql001\files\export.csv' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at Dynamics.Ax.Application.ImportGPinventTrans.Findandprocess() in ImportGPinventTrans.FindAndProcess.xpp:line 33
at Dynamics.Ax.Application.ImportGPinventTrans.Run() in ImportGPinventTrans.run.xpp:line 3
at Dynamics.Ax.Application.BatchRun.runJobStatic(Int64 batchId) in BatchRun.runJobStatic.xpp:line 50
at BatchRun::runJobStatic(Object[] )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
at BatchIL.taskThreadEntry(Object threadArg)