using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using System.Data.SqlClient; namespace FilmAndEntertainmentSystem { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private string GetWebsiteHtml(string url) { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); stream.Dispose(); reader.Dispose(); return result; } private void btnGetHTML_Click(object sender, EventArgs e) { string html = this.GetWebsiteHtml(this.txtUrl.Text); this.wbHtmlpage.DocumentText = html; } private void btnScreenSave_Click(object sender, EventArgs e) { string html = this.GetWebsiteHtml(this.txtUrl.Text); this.wbHtmlpage.DocumentText = html; byte[] bytes = System.Text.Encoding.ASCII.GetBytes(html); // set up data connection SqlConnection cs = new SqlConnection("Data Source=MASTER\\MASTER;Initial Catalog=FilmDB;Integrated Security=True"); // Set up adapter manager SqlDataAdapter da = new SqlDataAdapter(); using (SqlCommand com = new SqlCommand("INSERT INTO Website (WebsiteImage) VALUES (@Image)", cs)) { com.Parameters.AddWithValue("@Image", bytes); cs.Open(); com.ExecuteNonQuery(); cs.Close(); } } private void btnRead_Click(object sender, EventArgs e) { string html = this.GetWebsiteHtml(this.txtUrl.Text); this.wbHtmlpage.DocumentText = html; byte[] bytes = System.Text.Encoding.ASCII.GetBytes(html); // set up data connection SqlConnection cs = new SqlConnection("Data Source=MASTER\\MASTER;Initial Catalog=FilmDB;Integrated Security=True"); // Set up adapter manager SqlDataAdapter da = new SqlDataAdapter(); // Data set DataSet ds = new DataSet(); da.SelectCommand = new SqlCommand("Select WebsiteImage From Website Where WebsiteID = 3", cs); da.Fill(ds, "Website"); cs.Open(); response.ContentType = "Image"; response.BinaryWrite(bytes); cs.Close(); } } }
// Set the content type and return the image Response.ContentType = "image/GIF"; bytes.Save(Response.OutputStream, ImageFormat.Gif);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)