Help: Saving HTML file using C# in Win app or Win service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to generate HTML files based on the some codes. One HTML file per
code. I have the link
(ex:http://123.234.345.456/WebPages/GetTestData.aspx?SomeCode=25), by passing
the code as parameter I will get the page displayed.

But I don't want to display it, instead save those files in one of the
network directories that can be accessed by our third party vended web based
application. How can I do this accessing and saving HTML files a directory
using C# in a windows app or Windows service? Any help?

Thanks in advance for your time and help,
Vijay
 
Is it that much difficult to provide solution? Is it the same for MSFTs too?
Please provide some workable solution I have an urgent need.

Thanks,
Vijay
 
HTML files are just text files.

You can just use a StreamWriter for saving the HTML string to a file.
 
But I need to somehow load the webpage using some control and get the HTML
source code and write (save) to the disk. Here is what I did:

My code does not seem to be working. Please take a look at it and provide
where I need to change. My debugger is coming to the first line of the
DocumentComplete event and that is it. It is not going to the second line nor
giving me any exception.

object oPage = "http://www.google.com";
axWebBrowser1.Navigate2(ref oPage);

' Event
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
UCOMIPersistFile oPersistFile = (UCOMIPersistFile)e.pDisp;
string xx = @"C:\MyWebPage.html";
oPersistFile.Save(xx, true);
}

Thanks,
Vijay


-------------------------------------------------------------------------------------------
 
Solution:
----------

private void button1_Click(object sender, System.EventArgs e)
{
string sURL = "www.google.com";
axWebBrowser1.Navigate(sURL);
}

// axWebBrowser1 event
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)

{

string sFileName = System.Windows.Forms.Application.StartupPath +
"\\ATC.htm";

UCOMIPersistFile oPersistFile =
(UCOMIPersistFile)axWebBrowser1.Document;

oPersistFile.Save(sFileName, true);

}
 
It that correct because even though it works, you are going outside the
scope of the event to get the Document property.

This wouldn't work write, if say, you threaded the thing and raised
multiple events simultaneously.

Every time the out of scope axWebBrowser1 object changed, you would be
changing the .Document property.
 
I guess it all depends on the requirement. The requirement I have is simple,
all I need to do is to wait till the document loaded (Async event). You might
be right in complex scenario.

But do you know how you can do it without form and placing the control on
the form. I guess Microsoft did not come up with such a thing, in the Browser
control, that just load into memory without displaying the page and get the
stream from the object. I don't know whether this is true in their new
release VS 2005. I guess, this scenario is really useful in Windows Service.
 
Back
Top