5 Replies Latest reply on Aug 18, 2016 9:53 PM by Mike Zboray

    AFFile.Upload() error "Illegal characters in path."


      Hi there,

      in our production server (Prod01), we are experiencing this issue with AF sdk call while uploading .png & .gif file types. (I didn't try all graphics file types)

      But if I upload xml file on the same production server, same method call, then the call will be successful.

      Prod01 server :

      af sdk =

      AF server : 2.7



      On another production server (prod02), -( yes we have 2 separate prod environments due to diff business entities)

      I can use the same code to upload any files (including png..no file extension), the upload would work!

      Prod02 server:

      af sdk =

      AF server 2.6


      Anyone can help me to pinpoint the problem? Currently this is a show stopper for clients using Prod01 server. Temp solution, manually uploading the png & gif file to server by using PSE instead of a custom program talks to af sdk.


      Thanks much


      SDK call



      Error message :-

      2016-08-18 12:49:55,324 [24] ERROR
      EnergyMetrics.Services.Common.Common -  [Update]  ||Exception||:

      Illegal characters in path.

      System.ArgumentException: Illegal characters
      in path.

      System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)

      System.IO.Path.GetFileName(String path)

      OSIsoft.AF.Asset.AFFile.Upload(String name, Stream stream)

        • Re: AFFile.Upload() error "Illegal characters in path."
          David Hearn

          The error is being thrown in .NET's System.IO.Path.GetFileName("logo.png") which will throw if the specified string contains one or more of the invalid characters defined in 'System.IO.Path.GetInvalidPathChars()'. So not sure why the same code would work on one client machine and not on the other. Could their be a different version of .NET on these machines? Maybe try passing in the full path to the original file name.

          1 of 1 people found this helpful
          • Re: AFFile.Upload() error "Illegal characters in path."
            Mike Zboray

            A number of the illegal path characters have no visible extent. For example anything in ascii range 0-31 is not visible but is illegal in a path. However they do add to string's length. I would just do quick debug and print the length of the file name for example:

            string fileName = "logo.png";
            Debug.Print("File name test: '{0}', Length: {1}", fileName, fileName.Length); // should be 8 for logo.png
            afFile.Upload(fileName, fileStream);