Save graph

Sep 24, 2012 at 6:19 PM

I am using NodeXL class libraries in own application and when I am trying to save a graph to a file, I am catching exception:

Smrf.NodeXL.Core.Graph.GetRequiredValue: A value with the key "~AllEdgeMetadataKeys" does not exist.
Parameter name: key

   at Smrf.AppLib.ArgumentChecker.ThrowArgumentException(String sMethodName, String sArgumentName, String sMessageDetails, Exception oInnerException)
   at Smrf.AppLib.ArgumentChecker.ThrowArgumentException(String sMethodName, String sArgumentName, String sMessageDetails)
   at Smrf.NodeXL.Core.GraphVertexEdgeBase.GetRequiredValue(String key, Type valueType)
   at Smrf.NodeXL.Adapters.GraphMLGraphAdapter.SaveGraphCore(IGraph graph, Stream stream)
   at Smrf.NodeXL.Adapters.GraphAdapterBase.SaveGraph(IGraph graph, Stream stream)


Also I would like to know if there is any way to save an undirected graph?

Sep 25, 2012 at 3:23 AM

On the second question, saving an undirected graph to GraphML (and it looks like you're using GraphML) is done the same way as saving a directed graph.  The graph's directedness will get saved as an attribute in the GraphML file.  Did you try this and it didn't work?

On the exception you're getting, please see the "GraphMLGraphAdapter Class" topic in the NodeXLApi.chm file that was included in the class libraries you downloaded, and then let me know if you still have questions.  Here is an excerpt:

"When saving a graph, the SaveGraph caller must add AllEdgeMetadataKeys and AllVertexMetadataKeys keys to the graph before calling SaveGraph."

-- Tony

Feb 3, 2013 at 3:30 PM
Dear Tony,

I am having the same problem with saving a graph using GraphML.
My problem is:
what exactly should I assign to "AllEdgeMetadataKeys" and "AllVertexMetadataKeys"?

thanks for your help!
Feb 3, 2013 at 3:55 PM
You should assign string array with names of attributes which you want to save for edges and vertex .

Example to save only vertex labels:
string[] keys = new string[]
nodeXLControl1.Graph.SetValue(ReservedMetadataKeys.AllVertexMetadataKeys, keys );
nodeXLControl1.Graph.SetValue(ReservedMetadataKeys.AllEdgeMetadataKeys, new string[] { }); // empty array if you didnt set edges attributes
Feb 3, 2013 at 4:06 PM
Thanks a lot for your help!