This project has moved and is read-only. For the latest updates, please go here.

Accessing local files from Custom Input Adapter

Aug 22, 2014 at 6:30 PM

I've implemented a Custom Input Adapter taking as Connection String Parameter a file name, in order to read the chosen file and extract measurements from it.
But whatever file name I am giving (absolute or relative path, from the openPDC folder or not, etc.), I get an System.UnauthorizedAccessException (running openPDC Manager with or without Admin rights).

Note that the exception is thrown only when the adapter is used inside openPDC. It works as expected when launched locally, without admin rights (e.g. for unit testing).

I'm using the same method as CsvInputAdapter to open the file in Read-Only mode:
m_inStream = new StreamReader(File.Open(m_fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Actually, the CSVInputAdapter itself isn't working. By default, it tries to access the file in "C:\Windows\system32\measurements.csv" ("C:\Windows\system32" seems to be the running folder).

Any suggestion about what could be wrong?
Thanks in advance.
Aug 22, 2014 at 6:56 PM
Hi Aldream,

The openPDC service, by default, runs as "NT Service\openPDC". This is a virtual service account which exists solely for the openPDC service to run under restricted privileges. The openPDC installer adds the this account to the "openPDC Admins" group and grants rights to files and subfolders in the openPDC installation directory. Therefore, the openPDC will not have the rights to access any files unless they are placed in some common applications folder (such as AppData) or the openPDC installation directory.

Given all of that, you have two options:
  1. Place the files in a directory that the openPDC can access.
  2. Modify the file permissions such that either the "NT Service\openPDC" account or the "openPDC Admins" group has access to it.
As for the CSVInputAdapter, you should be able to use an absolute path instead of a relative path via the connection string to get it to look in the right place.

Marked as answer by Aldream on 8/23/2014 at 7:14 AM
Aug 23, 2014 at 1:52 PM
Hi Staphen,

I tried solution 1 before (moving the required files in openPDC directory), but it somehow didn't work. However, your 2nd suggestion worked perfectly. The Adapters are now able to properly access the files.

Thanks a lot for the quick and useful reply.
All the best.