0

This is how I normally execute an aspx web form and get a string from the output:

public static string GetAspPageOutput(string page)
{
  string html;

  using (var sw = new StringWriter())
  {
    HttpContext.Current.Server.Execute(page, sw);

    html = sw.ToString();
  }

  return html;
}

How do I instead get a byte array?

Anders Lindén
  • 6,839
  • 11
  • 56
  • 109

1 Answers1

0

The suggestion is from this post https://stackoverflow.com/a/1745456/3646986. Use the StreamWriter instead of the StringWriter

MemoryStream ms = new MemoryStream();
StreamWriter writer = new StreamWriter(ms);
context.Server.Execute(virtualpath, writer);
var bytes = ms.toArray()
return bytes
Tommy Nguyen
  • 96
  • 1
  • 5