简体   繁体   中英

how to save aspx file as html file and folder to local machine or server

in my web application my client wants to save the current aspx page as html file and also save the related file(jquery, images...) in a folder. basically that what is being done in the background when you right click and press "save to" in the browser and I want to do that by a click of a button(webcontrol).

i found a piece of code that will save the html file itself but i don't know how to save also the related folder.

private void SavePageASHtml(string location)
    {
        StringWriter stringWriter = new StringWriter();

        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

        Page.RenderControl(htmlWriter);

        htmlWriter.Flush();

        FileStream fileStream = new FileStream(location, FileMode.Create);

        string siteString = stringWriter.ToString();

        byte[] byteArray = Encoding.UTF8.GetBytes(siteString);

        fileStream.Write(byteArray, 0, byteArray.Length);

        fileStream.Close();

        Response.End();

        Response.Redirect("~/PriceList.aspx");
    }

Simply right click on page and save html, it will save everything direcctly linked to the page,.ie, images,js and css

This is a pretty old article, but it shows how to save as an MHT file, which is quite close to what I believe you want:

http://www.eggheadcafe.com/articles/20040527.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM