Reputation: 7303
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?
Upvotes: 0
Views: 77
Reputation: 116
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
Upvotes: 0