C# Developers' Journal (original) (raw)

Re: UserControl output into an XmlNode

A continuation of my awkward question for any C# geeks reading.

Ok, I don'think I'm gonna find a convenient way to do it the way I'd hoped, so I've started thinking about rendering the control into a Stream and XmlDocument.Load-ing that Stream into my XmlNode hierarchy.

Except I'm not getting anything out using Control.RenderControl(HtmlTextWriter):

public XmlDocument RenderXmlDocument() { MemoryStream stream = new MemoryStream();

  this.RenderControl(new HtmlTextWriter(new StreamWriter(stream)));

  byte[] streamContents = stream.ToArray();
  System.Text.StringBuilder sb = new System.Text.StringBuilder();

  foreach (byte tmp in streamContents)
     sb.Append(Convert.ToChar(tmp));

  HttpContext.Current.Trace.Write("EditSectionOrAsset",
     "Rendered control as \n\n[" + sb.ToString() + "]");

  XmlDocument control = new XmlDocument();
  control.Load(new XmlTextReader(new StreamReader(stream)));

  return control;

}

and nothing is getting written to the Trace.

Am I gonna have to work out how to do this without using the control?

Any and all suggestions gratefully received. Cross-posted to owenblacker, csharp and ms_dot_net.

Current Mood: pissed off