AnsweredAssumed Answered

Copy and Paste in C#

Question asked by HandsomePete on Oct 10, 2013
Latest reply on Oct 11, 2013 by HandsomePete
I'm creating a new copy/paste tool in c# to copy features in a feature class that have attachments (the stock copy/paste doesn't copy over the attachments).

I'm using this page for guidance.  Here is my code. 

IAttachment attachment = toolExtension.copyEnumAttachment.Next();
                    while (attachment != null)
                    {
                       
                        IMemoryBlobStream currAttachData = new MemoryBlobStreamClass();
                        currAttachData = attachment.Data;                      
                        m_attachmentManager.AddAttachment(newFeature.OID, new AttachmentClass { ContentType = attachment.ContentType, Data = currAttachData, Name = attachment.Name });
                        attachment = toolExtension.copyEnumAttachment.Next();
                    }

It will create an attachment but there doesn't appear to be any data associated with it.  You can see it listed in the attachment manager, but you can't open it and you can't save it to disk.  I was creating a new AttachmentClass object, then passing it to the AddAttachment method.  When I debugged it, there was an error stating that the attachment table didn't have a Global ID field  (even though it did) and the GlobalID property for the new AttachmentClass was blank.  When I open the attachment table (where the blobs are stored) I can see the GlobalID field and it's populated.

I'm doing all of this in an edit session.  Not sure if the problem is with the GlobalIDs or if I'm not actually passing the data to the new attachment.

Any help would be appreciated.

UPDATE: The error when I create the attachment class looks like this.  When you mouse over the GlobalID field, instead of the global id, is says:

"GlobalID = 'newFeatureAttachment.GlobalID' threw an exception of type 'System.Runtime.InteropServices.COMException'" 

Then when you mouse over that text, is pops up with:"{System.Runtime.InteropServices.ExternalException} = {"The table does not have a Global ID Field."}"

Outcomes