これが私のコードです。適切に動作するコードは、このコードを改善してCMSアプリケーションで使用するHTMLファイルを改善する方法を教えてくれます
正常に動作するように「Images」という名前のフォルダを作成してください
生成された HTML ファイルはプロジェクト フォルダに保存されます
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HTMLMaker.aspx.cs" Inherits="HTML5Demo.HTMLMaker" ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="Scriptmanager1" runat="server">
</asp:ScriptManager>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
<td colspan="2">
<b>HTML Maker</b>
</td>
</tr>
<tr>
<td>
<asp:Label Text="Title" ID="lblTitle" runat="server" />
</td>
<td>
<asp:TextBox runat="server" ID="txtTitle" />
</td>
</tr>
<tr>
<td>
<asp:Label Text="Image" ID="lblImage" runat="server" />
</td>
<td>
<asp:FileUpload runat="server" ID="fluImage" />
</td>
</tr>
<tr>
<td>
<asp:Label Text="Description" ID="lblDescription" runat="server" />
</td>
<td>
<asp:TextBox runat="server" ID="txtDescription" TextMode="MultiLine" Columns="25"
Rows="5" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button Text="Submit" ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
.cs ファイル
using System;
using System.IO;
using System.Text;
public partial class HTMLMaker : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string ImagePath = string.Empty;
string ImageName = string.Empty;
string FileName = Server.MapPath("~/") + txtTitle.Text + ".html";
if (fluImage.HasFile)
{
ImageName = DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(fluImage.FileName);
ImagePath = Server.MapPath("~/Images/") + ImageName;
fluImage.SaveAs(ImagePath);
}
using (FileStream fs = new FileStream(FileName, FileMode.Create))
{
using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine("<!DOCTYPE html>");
w.WriteLine("<html lang=\"en\">");
w.WriteLine("<head>");
w.WriteLine("<title>" + txtTitle.Text + "</title>");
w.WriteLine("</head>");
w.WriteLine("<body>");
w.WriteLine("<div>");
w.WriteLine("<img src='Images/" + ImageName + "' alt=" + fluImage.FileName + " />");
w.WriteLine("</br>");
w.WriteLine("<div>");
w.WriteLine(txtDescription.Text);
w.WriteLine("</div>");
w.WriteLine("</div>");
w.WriteLine("</body></html>");
w.Dispose();
}
fs.Dispose();
}
}
}
// 暗号化 && 説明 // public class EncryptionDecryption {
public EncryptionDecryption()
{
}
private static string keyString = "552F79D3-1F36-48ab-934C-4629C2274D43";
private const string strTamperProofKey = "astkvsnanvpi";
public static string TamperProofStringEncode(string strValue, string strKey)
{
System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strKey));
return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(strValue)) + System.Convert.ToChar("-") + System.Convert.ToBase64String(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strValue)));
}
public static string TamperProofStringDecode(string strValue, string strKey)
{
String strDataValue = "";
String strCalcHash = "";
strValue = strValue.Trim();
strValue = strValue.Replace(" ", "+");
System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
mac3des.Key = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strKey));
try
{
strDataValue = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(strValue.Split(System.Convert.ToChar("-"))[0]));
strCalcHash = System.Text.Encoding.UTF8.GetString(mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strDataValue)));
}
catch
{
throw new ArgumentException("Invalid TamperProofString");
}
return strDataValue;
}
public static string GetEncrypt(string value)
{
if (new HandleNull().CheckNull<string>(value).Trim().Length == 0) return value;
return TamperProofStringEncode(value, strTamperProofKey);
}
public static string GetDecrypt(string value)
{
if (new HandleNull().CheckNull<string>(value).Trim().Length == 0) return value;
return TamperProofStringDecode(value, strTamperProofKey);
}
}