Đây là giải pháp nhanh chóng của tôi thu thập dữ liệu trang web địa phương của bạn cho tệp .aspx và tạo tệp .html bên cạnh html.
protected void ButtonGenerate_Click(object sender, EventArgs e)
{
RecursivelyGenerateHtmlFiles(Server.MapPath("~/"), new DirectoryInfo(Server.MapPath("~/")));
}
private void RecursivelyGenerateHtmlFiles(string root, DirectoryInfo folder)
{
foreach (var aspxPage in folder.GetFiles("*.aspx"))
{
var destination = aspxPage.FullName.Substring(0, aspxPage.FullName.Length - 4) + "html";
if (File.Exists(destination))
File.Delete(destination);
var url = "http://" + Request.Url.Authority + "/" + aspxPage.FullName.Replace(root, "");
var request = HttpWebRequest.Create(url);
File.WriteAllText(destination, new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd());
}
foreach (var subDirectory in folder.GetDirectories())
{
RecursivelyGenerateHtmlFiles(root, subDirectory);
}
}
Làm việc cho tôi.
Ngoài ra, bạn có thể chỉnh sửa tệp .bat để tạo thư mục có tất cả các tệp .html từ trang web của bạn. Điều này hữu ích khi tạo quảng cáo cho một bản sao phẳng.
set folder="Generated"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
cd /d ..
xcopy /r /d /i /s /y /exclude:exclude.txt PAHtml Generated
Đây là loại trừ.tệp txt để sử dụng
.dll
.cs\
.aspx
.pdb
.csproj
.user
.vspscc
.config
Nguồn
2012-08-14 19:41:32
Một câu hỏi rất thú vị! – User
Tôi rất vui vì bạn đã chỉnh sửa tiêu đề. Tôi nghĩ "nên đặt 'vào trang HTML'" ngay sau khi tôi đăng :) – joshcomley
Tôi đã làm rõ tiêu đề cho bạn. – Soviut