Having trouble using aaApi_IsDirectory and aaApi_FileExist in a C# Wrapper

Hi,

I am having a bit of trouble with the following two functions. I don't know exactly where the problem is occuring. It could be because I am passing it a wrong path as a string. It could also be that I am not marshaling the string correctly to work with the C# wrapper.

Below is how I have my wrapper set up.

[DllImport("C:\\Program Files (x86)\\Bentley\\ProjectWise\\bin\\DMSGEN.DLL", CharSet = CharSet.Unicode)]
public static extern bool aaApi_IsDirectory(string FolderPath);

[DllImport("C:\\Program Files (x86)\\Bentley\\ProjectWise\\bin\\DMSGEN.DLL", CharSet = CharSet.Unicode)]
public static extern bool aaApi_FileExist(string FilePath);

Below is my usage with an example path

string TestFilePath = "pw:\\\\111.111.111.111:TESTSERV01\\Documents\\Projects\\Dams\\";

bool bool_ProjectWiseLocationExists = PwDotNet.aaApi_IsDirectory(TestFilePath);

string TestFile = "pw:\\\\111.111.111.111:TESTSERV01\\Documents\\Projects\\Dams\\File.pdf";

bool bool_ProjectWiseFileExists = PwDotNet.aaApi_FileExist(TestFile );

The bools always return false although I have the file and the path in ProjectWise. How can I pass it a string or set up the wrapper correctly in order to check for a file path or location.

Do I need to log into the projectwise datasource first? I can do that, but I would have to build this to check all my datasources.

Thanks for the help,

James

  • aaApi_IsDirectory and aaApi_FileExists are "wrappers" in the PW SDK for something similar to https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathisdirectorya They are for file system paths, not ProjectWise URL or URN's.

    Why not just use .NET's methods for checking if a path is a directory or a file?  https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.exists?view=netframework-4.7.2 for file system objects?

    As for checking to see if a PW URL or a PW URN is a folder or a file, try this API function:

       [DllImport("dmscli.dll", CharSet = CharSet.Unicode)]
        public static extern bool aaApi_MonikersToStrings([In]int lCount, [In]IntPtr[] pMonikers,
            [Out]StringBuilder[] sArrayMonikers, System.Int16 flags);
    

    And then examine the "parts".

    There might be a more direct way, but I haven't had the need, so if anyone else has a more direct method, PLEASE POST!

    Or you could parse out the text after "pw:...Documents" and use aaApi_GetProjectIdByPath, and if that fails, parse off the last "part" and see if that is a folder, and if it is, see if that last part is a document in that folder.  Of course this would assume that the string you are parsing contains a "path", not a GUID.

    Answer Verified By: James Kennedy 

  • Hey Dan,

    Thank you for the reply. I was mistaken and though they were for ProjectWise URL/URNs. What I was trying to accomplish was to check and see if a Folder/Project/Document existed in ProjectWise given that I had a path.

    Your suggestion of aaApi_GetProjectIdByPath didn't work out because I couldn't find a function for it, however using that same idea I used the two functions aaApi_GetProjectIdByNamePath and aaApi_SelectDocumentsByNameProp.

    Here are my wrappers

    [DllImport("C:\\Program Files (x86)\\Bentley\\ProjectWise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
    public static extern int aaApi_GetProjectIdByNamePath(string lpctstrPath);

    [DllImport("C:\\Program Files (x86)\\Bentley\\ProjectWise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
    public static extern int aaApi_SelectDocumentsByNameProp(int lProjectId, string lpctstrFileName, string lpctstrName, string lpctstrDesc, string lpctstrVersion);

    Here is my implementation

    string_ProjectWiseLocation = "Projects\\TestFolder\\TestLastFolder\\"

    int int_ProjectIDOfPWLocation = PwDotNet.aaApi_GetProjectIdByNamePath(string_ProjectWiseLocation);

    string_CurrentDocumentName = "TestPdf.pdf"

    int int_NumberOfDocumentsMatchingSelection = PwDotNet.aaApi_SelectDocumentsByNameProp(int_ProjectIDOfPWLocation, string_CurrentDocumentName, null, null, null);

    My objective is to mainly test if they exist or not as I already have the path, but I implicitly have to get the ProjectID first in order to look for the document in that ProjectID.

    As you also know, the string of ProjectWise Location is a path of everything after the \\documents\\ portion of a file path. 

  • Sorry, "aaApi_GetProjectIdByPath" was a typo by me, "aaApi_GetProjectIdByNamePath()" as you discovered, was what I meant...

    FWIW, Dave Brumbaugh has made his "PWWrapper" code available from GitHub https://github.com/DaveBrumbaugh/MostOfDavesClasses-CSharp-Wrappers-For-ProjectWise which can save you a lot of time trying to come up with P/Invoke ([DllImport ...]).  Not everything in the PW SDK is in there, but many of the functions that are commonly used in customizations.

    In his source you will find what I call "helper functions" (or methods depending how technical you want to get!) such as SetAttributesValuesFromColumnIds() and other useful things!

    You may also want to get Dave's DllExporterNet4 package from Nuget which allows you to be able to call static methods from native code, which can be handy if you want to write a function in C# but want to be able for ProjectWise to call it (such as a function defined in an .mrr file).