Retrieving attachment information
Other than using an Attachment Manager to add new attachment information (attachment objects) to features, you can also use it to retrieve the attachment information. Attachment information is created when you add new attachment objects, or for the attachments existing in the database, their information downloads automatically when you perform a feature download operation using a FeatureSyncAgent. This allows you to get some idea about the attachments before downloading.
Once you have the information about attachments, retrieve them using an AttachmentManager object. This topic shows how to do this using an AttachmentManager.
In the samples below, retrieve information about attachments using one of the overloaded AttachmentManager.GetAttachments methods.
The GetAttachments methods retrieves the attachment information in local storage. If you want to download the attachment files, refer to Synchronizing attachments.
- The following shows retrieving a list of attachment information from a single feature. Returned attachment objects can be in different edit states.
//Retrieve the list of attachments belonging to feature 615 IList<Attachment> attachments = manager.GetAttachments(615);
- The following shows retrieving a list of attachment information using a list of feature IDs. Again, attachment objects can be in different edit states.
//Retrieve the list of attachments belonging to features 615 and 922 IList<int> fids = new List<int>(new int [] {615, 922}); IList<Attachment> attachments = manager.GetAttachments(fids);
- The following shows retrieving a list of attachment information based on a QueryFilter against the FeatureSource and EditState of the attachments. Similar to the EditState of a FeatureSource, if an attachment object is created in local storage but not uploaded, its EditState is added. If it resides in the back-end database, it's in the Original EditState. If an original feature is deleted, it's marked Deleted.
//Retrieve the list of added attachments belonging to features 615 and 922, QueryFilter qf = new QueryFilter("OBJECTID = 615 OR OBJECTID = 922"); EditState editState = EditState.Added; IList<Attachment> attachments = manager.GetAttachments(qf, editState);