简体   繁体   English

如何将 aspx 文件另存为 html 文件和文件夹到本地计算机或服务器

[英]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.在我的 web 应用程序中,我的客户希望将当前的 aspx 页面保存为 html 文件,并将相关文件(jquery、图像...)保存在一个文件夹中。 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).基本上,当您右键单击并在浏览器中按“保存到”时在后台执行的操作,我想通过单击按钮(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.我找到了一段代码可以保存 html 文件本身,但我不知道如何保存相关文件夹。

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只需右键单击页面并保存 html,它将保存直接链接到页面的所有内容,即图像、js 和 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:这是一篇相当古老的文章,但它展示了如何保存为 MHT 文件,这与我认为您想要的非常接近:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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