title: Inserting an image into a Rich Text File in .NET
body: <p>I am attempting to insert an image into a rich text file. I have read some of the answers already, but I'm not getting it quite right. The code I am using is as follows:</p>
  
  <pre><code>            string[] imgfiles = Directory.GetFiles(dirin, "*.png");
              foreach (string imageFileName in imgfiles)
              {
                  var someImage = Image.FromFile(imageFileName);
                  MemoryStream memStream = new MemoryStream();
                  someImage.Save(memStream, ImageFormat.Png);
                  byte[] imgbytedata = memStream.ToArray();
                  memStream.Close();
                  memStream.Dispose();
                  StringBuilder sb = new StringBuilder();
                  for(int i = 0; i &lt; imgbytedata.Length; i++)
                  {
                      sb.Append(imgbytedata[i]);
                  }
                  var imgstr = "{" + string.Format("\\pict\\pngblip\\picw{0}\\pich{1}\\picwgoal{0}\\pichgoal{1}\\bin binary {2}", someImage.Width, someImage.Height, sb.ToString()) + "}";
                  sb = null;
  
                  rtb.AppendText(imgstr);
              }
  </code></pre>