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

谁说胖子不能爱 提交于 2019-12-11 06:35:37

问题


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");
    }

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/6558204/how-to-save-aspx-file-as-html-file-and-folder-to-local-machine-or-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!