// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Text; using System.Text.RegularExpressions; public class ViewMove : Stream { private Stream real; private Stream temp; public ViewMove(Stream real) { this.real = real; this.temp = new MemoryStream(); } public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override long Length { get { return temp.Length; } } public override long Position { get { return temp.Position; } set { throw new NotSupportedException(); } } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin direction) { throw new NotSupportedException(); } public override void SetLength(long length) { throw new NotSupportedException(); } public override void Close() { temp.Close(); String html = Encoding.UTF8.GetString(((MemoryStream)temp).ToArray()); int startix = html.IndexOf(@" 0) { int endix = html.IndexOf("/>", startix) + 2; string viewstate = html.Substring(startix, endix - startix); html = html.Replace(viewstate, ""); html = html.Replace("", viewstate + ""); } byte[] b = Encoding.UTF8.GetBytes(html); real.Write(b, 0, b.Length); } public override void Flush() { temp.Flush(); } public override void Write(byte[] buffer, int offset, int count) { temp.Write(buffer, offset, count); } }