当用户单击按钮时,我必须创建一个功能,而不是在 VS 中的项目名称中动态生成 html 文件,然后在新选项卡中打开它。
我在客户端的代码:
<asp:button ID="BtnGenrateHTML" runat="server" text=" Generate HTML " OnClick="btnAddnew_Click" />
我在服务器端的目录代码中创建了一个文件,如下所示: protected void btnAddnew_Click(object sender, EventArgs e) { string sFileFullName; 字符串 sFilePath; 字符串 sFileName;
string strHTMLGrid = "";
strHTMLGrid = strHTMLGrid + "Dear Customer,<BR><BR> Please provide below OTP to complete registration <BR><BR> ";
strHTMLGrid = strHTMLGrid + "<BR><BR> This OTP is valid for 15 minutes.";
strHTMLGrid = strHTMLGrid + "<BR><BR> With Best Regards - Indiefy";
This is not working //strHTMLGrid= strHTMLGrid + "<a href="abc.html/">thesitewizard.com</a>"
sFilePath = Server.MapPath("");
sFileName = "abc.html";
sFileFullName = sFilePath + "\\" + sFileName;
if (!Directory.Exists(sFileFullName))
{
Directory.CreateDirectory(sFilePath);
}
// if it exist than to delete it.
if (System.IO.File.Exists(sFileFullName))
{
System.IO.File.Delete(sFileFullName);
}
// If it deleted than we need to create it again
FileStream fs = new FileStream(sFileFullName, FileMode.Create);
using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine(strHTMLGrid);
}
fs.Close();
}
如何abc.html
通过单击按钮打开我的文件?请指导我该怎么做。
这在服务器端不起作用:
strHTMLGrid= strHTMLGrid + "<a href="abc.html/">thesitewizard.com</a>"