Copy out document aaApi_giveoutdocument & aaapi_fetchdocumentfromserver

I am looking for the best way to copy out docments from PW. I am using c# to login to pw and copy out documents. I am getting a error 58019 when I try to use the aaapi_giveoutdocument or aaapi_fetchdocumentfromserver. should these functions allow a document to be copied out or is there a better function to use.

Where can I find more information about error code 58019.

Parents
  • Alan,

    In my early days of consulting, a mentor told me that the "right" answer to any question a client might ask, particularly if they include the phrase, "the best", or something similar, was "It depends."

    The "best way" DEPENDS upon what you are trying to accomplish. Firstly, what do you mean by "copy out", as that has a specific meaning in the ProjectWise world, but many folks mean different things when they mention "copy out". You mention both aaApiFetchDocumentFromServer() as well as aaApi_GiveOutDocument(), but have you tried aaApi_CopyOutDocument()? And if not, why not? Does it not do what you need it to do? Something specific that the other two functions can do that aaApi_CopyOutDocument() can't do? (Just asking...)

    To your question, "should these functions allow a document to be copied out?" You can copy out (ProjectWise meaning) a document with any of the functions mentioned above. Which one to use depends on your needs. The documentation mentions that aaApi_GiveOutDocument() is the same as calling aaApi_FetchDocumentFromServer() with specific parameters. And aaApiCopyOutDocument() is the same as calling aaApi_FetchDocumentFromServer() with specific parameters. So, you can infer that aaApi_FetchDocumentFromServer() is the general case, and the other two just make it easier for you as a developer to call the underlying function with the "right" parameters for a particular need. Make sense?

    You can find most error codes by searching the SDK help document (or the *.h files). The help file shows this:

    #define AAERR_DMS_ERR_NO_WORK_DIR 58019

    You can (and IMHO, should) use aaApi_GetLastErrorMessage() and aaApi_GetLastErrorDetail() in addition to aaApi_GetLastErrorId() to find out more about the error placed on the error stack by most API functions that fail (see each function's documentation for details).

    I suspect that in this case, the ProjectWise user you are using for your calls hasn't created a working directory yet, at least not on the machine that your are running your code on. The user may not even have a working directory defined.

    By default, ProjectWise Explorer will prompt the user to create one if it can't find one defined for the user or if it doesn't exist. That a feature of PWE, not the APIs. You as the developer need to be a bit "defensive" in that you can't assume that everything needed for your application to "work" is already "in place". It's pretty common in custom applications to have code that checks to see if the current user has the rights/abilities/resources needed before continuing. You can check to see if the current user has a working directory defined with aaApi_GetUserStringSetting(), and then you can use the results to determine if the directory exists, or if you need to create it, etc.

    Also, in general, when having problems with code, it is always helpful to see the specific code in question, or at least a snippet so that the general context as well as the specifics are available to anyone willing to help. Posting additional information such as what version of ProjectWise you are using, etc. can be helpful as well because API specifics can change over the life of a product. And since you mentioned that you are using C#, it would be helpful to see how you are calling the unmanaged code (P/Invoke specifics, etc.)

    Hope this helps!

Reply
  • Alan,

    In my early days of consulting, a mentor told me that the "right" answer to any question a client might ask, particularly if they include the phrase, "the best", or something similar, was "It depends."

    The "best way" DEPENDS upon what you are trying to accomplish. Firstly, what do you mean by "copy out", as that has a specific meaning in the ProjectWise world, but many folks mean different things when they mention "copy out". You mention both aaApiFetchDocumentFromServer() as well as aaApi_GiveOutDocument(), but have you tried aaApi_CopyOutDocument()? And if not, why not? Does it not do what you need it to do? Something specific that the other two functions can do that aaApi_CopyOutDocument() can't do? (Just asking...)

    To your question, "should these functions allow a document to be copied out?" You can copy out (ProjectWise meaning) a document with any of the functions mentioned above. Which one to use depends on your needs. The documentation mentions that aaApi_GiveOutDocument() is the same as calling aaApi_FetchDocumentFromServer() with specific parameters. And aaApiCopyOutDocument() is the same as calling aaApi_FetchDocumentFromServer() with specific parameters. So, you can infer that aaApi_FetchDocumentFromServer() is the general case, and the other two just make it easier for you as a developer to call the underlying function with the "right" parameters for a particular need. Make sense?

    You can find most error codes by searching the SDK help document (or the *.h files). The help file shows this:

    #define AAERR_DMS_ERR_NO_WORK_DIR 58019

    You can (and IMHO, should) use aaApi_GetLastErrorMessage() and aaApi_GetLastErrorDetail() in addition to aaApi_GetLastErrorId() to find out more about the error placed on the error stack by most API functions that fail (see each function's documentation for details).

    I suspect that in this case, the ProjectWise user you are using for your calls hasn't created a working directory yet, at least not on the machine that your are running your code on. The user may not even have a working directory defined.

    By default, ProjectWise Explorer will prompt the user to create one if it can't find one defined for the user or if it doesn't exist. That a feature of PWE, not the APIs. You as the developer need to be a bit "defensive" in that you can't assume that everything needed for your application to "work" is already "in place". It's pretty common in custom applications to have code that checks to see if the current user has the rights/abilities/resources needed before continuing. You can check to see if the current user has a working directory defined with aaApi_GetUserStringSetting(), and then you can use the results to determine if the directory exists, or if you need to create it, etc.

    Also, in general, when having problems with code, it is always helpful to see the specific code in question, or at least a snippet so that the general context as well as the specifics are available to anyone willing to help. Posting additional information such as what version of ProjectWise you are using, etc. can be helpful as well because API specifics can change over the life of a product. And since you mentioned that you are using C#, it would be helpful to see how you are calling the unmanaged code (P/Invoke specifics, etc.)

    Hope this helps!

Children
  • Thanks for the information. I was able to get more information from the aaApi_GetLastErrorId() function. I had to change how I was importing the dmscli.dll. I added the CharSet = CharSet.Unicode.

    [DllImport("C:\\Program Files (x86)\\Bentley\\ProjectWise\\bin\\DMSCLI.DLL", CharSet = CharSet.Unicode)]
    public static extern bool aaApi_FetchDocumentFromServer(uint ulFags, int lProjectId, int lDocumentId, string lpctstrWorkdir, StringBuilder lptstrFileName, int lBufferSize);

    I was able to find the flags in the api documentation for copyout. AADMS_DOCFETCH_COPYOUT.