I tried to figure this out when i first started programming in c# and quickly gave up after many searches.
Unfortuantly I not tried since to figure out a solution to this. I have worked in webrequest a bit and Base64string Conversion a great deal. I dont Know if this will help but here is a way to convert the entire page to base64string.
using System;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private byte[] downloadedData;
public Form1()
{
InitializeComponent();
}
private void DownloadPage(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
byte[] buffer = new byte[1024];
int dataLength = (int)response.ContentLength;
progressBar1.Maximum = dataLength;
lbProgress.Text = "0/" + dataLength.ToString();
Application.DoEvents();
MemoryStream memStream = new MemoryStream();
while (true)
{
int bytesRead = stream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
progressBar1.Value = progressBar1.Maximum;
lbProgress.Text = dataLength.ToString() + "/" + dataLength.ToString();
Application.DoEvents();
break;
}
else
{
memStream.Write(buffer, 0, bytesRead);
if (progressBar1.Value + bytesRead <= progressBar1.Maximum)
{
progressBar1.Value += bytesRead;
lbProgress.Text = progressBar1.Value.ToString() + "/" + dataLength.ToString();
progressBar1.Refresh();
Application.DoEvents();
}
}
}
downloadedData = memStream.ToArray();
stream.Close();
memStream.Close();
}
private void SavePage(string path, byte[] Data)
{
StreamWriter sw = new StreamWriter(path);
sw.Write(Convert.ToBase64String(Data));
sw.Flush();
sw.Close();
}
private void button1_Click(object sender, EventArgs e)
{
DownloadPage(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
return;
SavePage(sfd.FileName, downloadedData);
}
}
}