public static void DoExportGraph(Graph.Gdi.GraphDocument doc, string fileName, Graph.Gdi.GraphExportOptions graphExportOptions) { if (!System.IO.Path.IsPathRooted(fileName)) throw new ArgumentException("Path is not rooted!"); var fileNamePart = System.IO.Path.GetFileName(fileName); var pathPart = System.IO.Path.GetDirectoryName(fileName); if (true && !System.IO.Directory.Exists(pathPart)) { System.IO.Directory.CreateDirectory(pathPart); } using (Stream myStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { doc.RenderToStream(myStream, graphExportOptions); myStream.Close(); } }