Question Status

Unanswered
Freya Tan asked a question on 10 Apr 2013 7:40 PM

Hi,

I have a batch job that will import a file. The import file is saved in a different server (not where the AOS resides). The batch job runs if I just use a directory where the AOS is installed. Also, if I run the class manually (not as batch job) and I use a network directory, I can import the file successfully. 

Any ideas?

Thanks

Reply
Bilal Issa responded on 11 Apr 2013 12:45 AM

Hi,

can you please write the error you are getting?

Regards,

Bilal

Reply
Freya Tan responded on 11 Apr 2013 1:43 AM

I don't get any error. The batch job succeeds. But the problem, it never execute the file in the directory.

Reply
Dominic Lee responded on 11 Apr 2013 1:51 AM

Check the network folder access right, Make sure AOS service account can access the network folder.

Then try again with the network folder setup.

kind regards,

Dominic Lee

My blog | PBC

This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Reply
Bilal Issa responded on 11 Apr 2013 1:57 AM

Hi,

can you please let me know the code you are using?  are you using WinAPISerevr, or something else?

Regards,

Bilal

Reply
Freya Tan responded on 11 Apr 2013 2:06 AM

I'm using System.IO not WinAPIServer.

Reply
Bilal Issa responded on 11 Apr 2013 2:18 AM

so are using the following code?

      filepermission = new FileIOPermission(fileName, 'R');

       interopPermission = new InteropPermission(InteropKind::ClrInterop);

       permissionSet = new Set(Types::Class);

       permissionSet.add(interopPermission);

       permissionSet.add(filepermission);

       CodeAccessPermission::assertMultiple(permissionSet);

        System.IO.File::Move(fileName,newFileName);

       CodeAccessPermission::revertAssert();

Reply
Freya Tan responded on 11 Apr 2013 2:53 PM

I'm getting the file list from the directory first. My method looks like:

// loop all files that fit the required format

   InteropPermission   interopPerm;

   System.Array        files;

   int                 i;

   container           fileList;

   ;

   interopPerm = new InteropPermission(InteropKind::ClrInterop);

   interopPerm.assert();

   files = System.IO.Directory::GetFiles(@_sourceDirectory, #FileExtension);

   for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )

   {

       fileList = conins(fileList, conlen(fileList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));

   }

   return fileList;

Then I loop on the container to process each file. I open the file and assign it to a CommaIo. My code looks like:

boolean openFile(Filename   _fileName)

{

   boolean     ret = true;

   ;

   csvFile = null;

   csvFile = new CommaIo(_fileName, #io_read);

   if(!csvFile)

   {

       //Error when opening file

       ret = checkFailed("@SYS69639");

   }

   return ret;

}

Reply
Bilal Issa responded on 14 Apr 2013 4:56 AM

please try to use the follwoing code to get the files list.

   System.IO.DirectoryInfo     directory;

   System.IO.FileInfo[]        files;

   System.IO.FileInfo          file;

   InteropPermission           permission;

   str         fileName;

   counter     filesCount;

   counter     loop;

   container   mathchingFiles;

   ;

   permission  = new InteropPermission(InteropKind::ClrInterop);

   permission.assert();

   directory   = new System.IO.DirectoryInfo(_folderPath);

   files       = directory.GetFiles(_filePattern);

   filesCount  = files.get_Length();

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

   {

       file            = files.GetValue(loop);

       fileName        = file.get_FullName();

       mathchingFiles  +=  fileName ;

   }

   CodeAccessPermission::revertAssert();

   return mathchingFiles;

Reply