How to save html file and respective dependent files in server

Hi All

Currently iam working with web application using C# ,my requirement is need to save a html file ,whenever saving a file the related image files should save in a folder

Ex:
When you click http://aspalliance.com/150 in URL when we use save as we can save it as HTML file and the related images are saved in related folder

I need to implement the same concept

Could any one please guide me

Thanks a lot




Answer this question

How to save html file and respective dependent files in server

  • lewiscobley

    In 2003, simply get the webBrowser control by right clicking on your toolbar and click on the add/remove items menu option. Once the dialog appears, click on the COM Components and then click on the browse button. Goto your system 32 directory and shdocvw.dll. Add it to the COM Components and click okay.

    You now have a webBrowser control.

    As for the System.Windows.Forms.HtmlElementCollection, go to references and again to the COM references and look for the Microsoft HTML Object Library. Add it to your references.

    Add using mshtml to the top of the form's class and then:

    inside the form load:

    axwebBrowser1.Navigate "HTTP://www.Microsoft.com";

    Add the control to the form and double click on it. The event for document complete should be made r you. inside of it:

    mshtml.IHTMLElementCollection img = AxWebBrowser1.Document.GetElementsByTagName("IMG");

    for (int x=0;x<img.length;x++)

    {

    Console.Out.WriteLine(img.item[x].src);

    }

    HTH


  • -fej-

    The webbrowser control can navigate to a webpage and provide you with an HTML DOM object.

    You can then:

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

    {

    System.Windows.Forms.HtmlElementCollection A = webBrowser1.Document.GetElementsByTagName("IMG");

    for (int x = 0; x < A.Count; x++)

    {

    //at this point, you can save the urls to a database or file

    //you can also url to the file itself and copy the file to your machine...this can also be very illegal, too.

    Console.Out.WriteLine(A[x].GetAttribute("src").ToString());

    }

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    webBrowser1.Navigate(http://www.yahoo.com);

    }


  • Zeb Macahan

    can you give some detail description about it

  • Mustafa AYG&amp;#220;N

    Probably you can using regular expression to find any external links (aka <img src="" /> etc) in the targeting html file, and then save those files pointed by those links, and then save the html text file finally.

    Sheva


  • Chris To

    thank you

    but iam using .net 2003 there is no option of webbrowser control and there html control html file option which having the event load and unload no other events are there and for System.Windows.Forms.HtmlElementCollection does not exist mean htmlelementcollection does not exist in the forms so pleaseif avilable please send which is support to 2003



  • How to save html file and respective dependent files in server