Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将图像添加到使用file.create方法创建的html文件中_C# - Fatal编程技术网

C# 如何将图像添加到使用file.create方法创建的html文件中

C# 如何将图像添加到使用file.create方法创建的html文件中,c#,C#,我正在使用下面的代码创建html文件 string path = HttpContext.Current.Server.MapPath("Attachments/test.html"); // Delete the file if it exists. if (File.Exists(path)) { File.Delete(path); } // Create the file. using (FileStream fs = File.Create(path, 1024)) {

我正在使用下面的代码创建html文件

string path = HttpContext.Current.Server.MapPath("Attachments/test.html");

// Delete the file if it exists.
if (File.Exists(path))
{
    File.Delete(path);
}

// Create the file.
using (FileStream fs = File.Create(path, 1024))
{
    byte[] info = new UTF8Encoding(true).GetBytes("<html><body><div>Test</div></body><html>");

    // Add some information to the file.
    fs.Write(info, 0, info.Length);
}
string path=HttpContext.Current.Server.MapPath(“Attachments/test.html”);
//删除文件(如果存在)。
if(File.Exists(path))
{
删除(路径);
}
//创建文件。
使用(FileStream fs=File.Create(路径1024))
{
byte[]info=新的UTF8Encoding(true).GetBytes(“测试”);
//向文件中添加一些信息。
fs.Write(信息,0,信息长度);
}
我想将图像添加到此html文件。。。 如何将图像添加到此html文件。

byte[]info=new UTF8Encoding(true).GetBytes(“Test”);
 byte[] info = new UTF8Encoding(true).GetBytes("<html><body><div>Test</div><img src='image.png' alt='your added image'/></body><html>");

您尝试了什么,在哪里失败了?您是否使用HTML编辑器将图像添加到HTML文件中以查看您希望执行的操作?你有没有在谷歌上搜索“HTML图像”?还有,哦,你当然应该确保HTML所指的图像资源在服务器/工具请求时实际提供。它可以在请求时动态生成。但是没有嵌入HTML,只有它的URI。