Moderator: Phil Barton
I am going to be using the API to maintain a special document in some of my orders' attachments collections (i.e. IOrder.DocumentImage collection). I see samples on how to create a new document via the API (IOrder.DocumentImage.CreateNew()) which works great for document creation and attachment to an order. However, I do not see class members, examples, or discussion of how to perform the other core operations of CRUD (Create, Read, Update, Delete). Specifically, how can I either update or delete attachments?
As far as updating, I have tried simply editing the attributes of an existing document that have changed (i.e. OriginalLocation and SubmittedDate) and then saving the order (IOrder.SaveOrder) and while I get no errors neither does the document's content update--it still shows the content it had when I created it while the date does update as expected.
As far as deleting an attached document I don't have anything to go on so not sure what to even try. If I can get update to work then delete is not that important but it seems like the API should support full CRUD operation since sooner or later someone will need it.
Sr. Software Architect
If I can't get a solution via the API then I will consider a solution via direct database access (although I don't relish it). I would appreciate, if that's the most direct route, if you could tell me what tables need to be updated if I'm going to delete an attached document so that I don't get my orders in an inconsistent/corrupted state. As I said, I realize this is dangerous and bad practice but if it comes to it I'll have no choice. Related to this, can you tell me if IOrder.LockStatus provides an accurate, real-time status of order locking?
1) Cursory experimentation indicates the lock status is not accurate. I could see the lock in SPAdmin but the API call indicated no lock and when I went to open the order r/w mode an exception was thrown that stated the order was locked.
2) As best I can tell from looking at keys in the SelectDb (on the DocumentImage table) and experimentation, it's pretty straightforward to directly manage attached documents via the API. A couple of items may save you time if you start deleting attachments via direct database access:
a) You can't delete a doc and add one back with the same name unless you save and reopen the order--the business logic won't know the original is gone so you'll get a duplicate document name exception
b) If you are also managing the physical files in the Image store remember that SoftPro Select marks everything in there as read-only so Flle.Delete will throw an exception "access denied" if you don't first set attributes to not-read-only using code like this:
Code: Select all
FileAttributes attrs = File.GetAttributes(strPath); attrs &= ~FileAttributes.ReadOnly; File.SetAttributes(strPath, attrs); File.Delete(strPath);