问题
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