private void RespondWithFile(File422 file, WebRequest req) { Stream str = file.OpenReadOnly(); string resp = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + str.Length + "\r\n" + "Content-Type: " + GetContentType(file.Name) + "\r\n\r\n"; // Write headers first byte[] buf = Encoding.ASCII.GetBytes(resp); req.WriteDirectResponse(buf, 0, buf.Length); buf = new byte[8192]; int count = str.Read(buf, 0, buf.Length); while (count != 0) { req.WriteDirectResponse(buf, 0, count); buf = new byte[8192]; count = str.Read(buf, 0, buf.Length); } str.Close(); }