Copy and Paste in C#

2323
1
Jump to solution
10-10-2013 09:57 AM
BrendanDwyer
Occasional Contributor
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."}"
0 Kudos
1 Solution

Accepted Solutions
BrendanDwyer
Occasional Contributor
Figured it out.  I called the editor.stopOperation method before adding the attachments.  Calling it after adding makes it allllllllll good.

btw I'm going to mark this as answered.  Not sure if it's kosher to answer your own questions, but I want to identify that the issue is resolved.

View solution in original post

0 Kudos
1 Reply
BrendanDwyer
Occasional Contributor
Figured it out.  I called the editor.stopOperation method before adding the attachments.  Calling it after adding makes it allllllllll good.

btw I'm going to mark this as answered.  Not sure if it's kosher to answer your own questions, but I want to identify that the issue is resolved.
0 Kudos