Adding the Link from anothert document

Hi All,
I need to add the GoLink objects from another document into existing document.
One document consists of many GoLinks. I want to add those GoLink Objects into existing one’s document.
It is giving one exceptions…
Exception :
The new value for GoDocument.LinksLayer must belong to this document.
I am trying to add one document’s GoLink object into another’s document.
Is it possible ? If Possible please help me.
Thanks in advance,
Natraj.

It appears that you are trying to share the GoLayer amongst GoDocuments (actually GoLayerCollections), and that is not supported.
You will need to create your own layer in the destination document (if you haven’t already) and then copy the GoObjects that you want from the source document. That’s easy to do with most objects–just call GoDocument.CopyFromCollection, passing it the source GoLayer. However, in the case of GoLinks, there are references to other objects (GoPorts) that need to be resolved correctly. Unless you are also copying over all of the ports/nodes that those links connect, you will need to somehow resolve those references correctly in the new document.
If it is the case that you are trying to copy links without copying their connected nodes, and that your destination document already contains all the nodes with their ports that your links will need, and that your destination document already has a layer with the same GoLayer.Identifier as your source layer, then you just need to do something like:
GoCopyDictionary env = dstDoc.CreateCopyDictionary();
// map each port in the source document to the corresponding port in the destination document
. . . for each srcPort in the source, find the corresponding dstPort in dstDoc
env[srcPort] = dstPort;
. . .
dstDoc.CopyFromCollection(srcLayer, false, false, new SizeF(), env);
Of course, the hard part if you have multiple ports on nodes is to figure out which port is which. That is something that is very application specific, and I can’t help you there.

Yes I need to Copy the link with its reference with its connected nodes.
Then only i can the map the ports with Link.
Then this way of code will help me ?GoCopyDictionary env = dstDoc.CreateCopyDictionary();
// map each port in the source document to the corresponding port in the destination document
. . . for each srcPort in the source, find the corresponding dstPort in dstDoc
env[srcPort] = dstPort;
. . .
dstDoc.CopyFromCollection(srcLayer, false, false, new SizeF(), env);

Now i can copy the objects and likns correctly.
But i couldn’t make the refernce between the ports and its links.
This is my problem.
Is there any way for this ?

I don’t understand your replies. Are you copying the nodes that are connected to the links that you want to copy?
If for every link you want to copy you are also copying the nodes that the link connects, then you can just call GoDocument.CopyFromCollection.
If you are not copying the nodes, because the destination document already has the nodes (and thus the ports) that you want to use, then you should use the code I listed above. That code explicitly creates a GoCopyDictionary and initializes it with mappings of ports in the source document to the corresponding ports in the destination document. Then you just call CopyFromCollection with all of your links, and they get copied and magically linked up to the ports in the destination document.

GraphDoc destdoc = tabshapewinow.View.Doc; foreach(GoObject obj in srcdoc) { GraphNode node = obj as GraphNode; if (node != null) destdoc .AddCopy(node,node.Location); }

foreach(GoObject obj in srcdoc)
{
GraphLink link = obj as GraphLink;

if (link != null)
{
GoObject linkObj = link.Copy();
destdoc .LinksLayer.Add(linkObj);
}
}
Through this code , i have copied Links and Ports to the destination document from source document. But the links are not get connected with the ports.I couldn’t get the reference of the Link.
In my case, Ports are dynamic.
Now , Can u able to understand my problem ?

I asked if you were copying the nodes.
I said that if you are copying the nodes, you could just call GoDocument.CopyFromCollection. You wouldn’t need to set up a GoCopyDictionary.
You seem to be copying the nodes. Hence you should just call GoDocument.CopyFromCollection.