title: 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll An unhandled exception of type
body: <p>I am creating a diagram designer and i add a button on it to save the GUI as an image. i create a class DiagramDesignerExporter and i have this code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  
  namespace DiagramDesigner
  {
      class DiagramDesignerExporter
      {
          public static void ExportToPng(UIElement target, string ImagePath)
          {
              // Prepare target-layout
              Size size = target.RenderSize;
              target.Measure(size);
              target.Arrange(new Rect(size));
          // Render diagram to bitmap
          RenderTargetBitmap renderBitmap =
              new RenderTargetBitmap(
                  (int)size.Width,
                  (int)size.Height,
                  96, 96,
                  PixelFormats.Pbgra32);
          renderBitmap.Render(target);
  
          // Convert bitmap to png
          PngBitmapEncoder encoder = new PngBitmapEncoder();
          encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
  
          using (FileStream fileStream = new FileStream(ImagePath, FileMode.Create))
          {
              encoder.Save(fileStream);
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I call it like this in the button:</p>
  
  <pre><code>DiagramDesignerExporter.ExportToPng(this, &lt;YourFullFilePath&gt;);
  </code></pre>
  
  <p>I am hoping for your help. Any suggestions will do. Thanks :)</p>