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 :
Microsoft Dynamics AX (Archived)

System.ArgumentException: The path is not of a legal form - while reading csv in batch

(1) ShareShare
ReportReport
Posted on by 3,945

Hi all,

Greetings of the day,

We are trying to read csv from a directory using batch job, but when batch job executes its thows error - System.ArgumentException: The path is not of a legal form .

Suggest us how do we proceed.

Thanks 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi.,

    Please specify the filepath in UNC format like  @"\\MachineName\Sample\Sample.csv". 

  • Gautam Profile Picture
    3,945 on at

    Hi Chaitanya ,

    Thanks for your reply,

    our path is somewhat like this  - C:\Import ,

    how do we convert it into UNC.

    Thanks .

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    UNC path in your case would be  @"C:\Import\Sample.csv"

  • Gautam Profile Picture
    3,945 on at

    Hi,

    here is my code , I have added "@" before file path but still no luck

    void readFilesFromDirectory(  )

    {

       System.IO.DirectoryInfo     directory;

       System.IO.FileInfo[]        files;

       System.IO.FileInfo          file;

       InteropPermission           permission;

       str                         _filePattern   = "*.csv";

       Table1                       tab;

       str                         _folderPath;

       str                         fileName;

       counter                     filesCount;

       counter                     fileCounter;

      System.Environment           env;

       ;

       try

       {

           _folderPath =  "@"+ "C:\Import";

           permission  = new InteropPermission(InteropKind::ClrInterop);

           permission.assert();

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

           files       = directory.GetFiles(_filePattern);

           filesCount  = files.get_Length();

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

           {

               file            = files.GetValue(fileCounter);

               fileName        = file.get_FullName();

               tab.Name = fileName; // storing file name in table

               tab.insert();

           }

           CodeAccessPermission::revertAssert();

       }

       catch(Exception::CLRError)

       {

       }

    }

    Thanks

    Gautam

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please try with the statement  _folderPath =  @"C:\Import";

  • Gautam Profile Picture
    3,945 on at

    Hi,

    I tried this piece of code _folderPath = @ledgerParameters.filepath // we are storing that file path in parameter table

    but it throws same exception : - System.ArgumentException: The path is not of a legal form.

      at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)

    Thanks

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    What is the value that getting stored in filepath field. Please use winapiserver::pathexists to check whether the  path is getting recognised or not.

  • Gautam Profile Picture
    3,945 on at

    Hi ,

    in file path field we are storing directory path from where we need to read csv.

    like - C:\Import

    Thanks

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans