Save File Dialog. (I have code, just need a little help fixing)
Hey,
Ok, so I did the save FIle dialog code and it works fine. But I can't figure out how to amke it so thta is will save the contents of the current page in the webbrowser. Here is the code:
privatevoid savePageToolStripMenuItem_Click(object sender,EventArgs e){
Stream myStream =null;SaveFileDialog saveFileDialog1 =newSaveFileDialog();saveFileDialog1.InitialDirectory =
"c:\\";saveFileDialog1.Filter =
"Webpage Html (*.html)|*.html|Text File (*.txt)|*.txt";saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory =
true;if (saveFileDialog1.ShowDialog() ==DialogResult.OK){
try{
if ((myStream = saveFileDialog1.OpenFile()) !=null){
using (myStream){
}
}
}
catch (Exception ex){
MessageBox.Show("Error: Could not save file from Browser. Original error: " + ex.Message);}
}
}
Thanks :)
By saying "saving the page in webbrowser" you probably want to save images and other objects in the page. You can get HTML source for the current page but you have to get other related files (image files, css, script files, if it is framed source page for each farme...). You have to create proper directories or put all the files in the same directory and change paths in the source web page.
Ok, so I guess I put that inbetween the brackets of:
using (myStream)
{
}
?
Or take out what I have and replace it with that?
Thanks :)
that is all true...it is loaded and works...
how about I use this:
//using (StreamReader sr = new StreamReader(webBrowser1.DocumentStream))//{// using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false))// {// sw.Write(sr.ReadToEnd());// }//}saveFileDialog1.OverwritePrompt =
true;saveFileDialog1.Title =
"Save Document";saveFileDialog1.Filter =
"Html File (*.html)|*.html|All Files (*.*)|*.*";if (saveFileDialog1.ShowDialog() == DialogResult.OK){
// Webbrowser1 save code here
}
where it says // Webbrowser1 save code here What would I put for it to save the Webpage Document...without or with images, whatever you want to give me is fine.
Thanks :)
I recall coding these dialogs way back but sort of moved on, this post came up in my search
as close to my question, not coding any more unless a patch can be had and I have to as part
of the answer to this topic, which I hope you don't mind my expansion.
On the dialog, can the default option be changed without recoding?
Some file saves revert back to the last type saved, if not you are locked in to the default.
I noticed IE 7.0 has three file types .mht, HTML only .htm/.html, and Webpage complete .htm/.html
which always comes up .mht an archive file that is 10x, at last comparison, as large as normal .htm
file saves, now called complete Webpage .htm/.html.
A coded patch I might try and compile, unless some where the dialog setting is present and
you can divulge and thanks.