htmlagilitypack을 사용하여 문서에 새 노드를 삽입하려고합니다.C#에서 html 문서에 새 노드 삽입
HtmlDocument ndoc = new HtmlDocument();
ndoc.Load(stream);
HtmlNode usern = HtmlNode.CreateNode("<img .... />");
usern.Attributes.Add("onclick", "javascript:document.location.href='/Home/Index';");
ndoc.DocumentNode.SelectSingleNode("id('main')").AppendChild(usern);
using (MemoryStream ms = new MemoryStream())
{
ndoc.Save(ms);
ms.Seek(0, System.IO.SeekOrigin.Begin);
fileBytes = ms.ToArray();
}
FileContentResult file = File(fileBytes, "text/html");
return file;
문제 : 새로운 노드 (IMG)가 삽입되지 않은 나는 FileContentResult 개체로 문서를 반환 한 후 노드를 삽입하고, 스트림에서 문서를 읽고있다. 이 코드를 사용하고 있고 스트림에서 문서를 읽고 FileContentResult로 반환 한 다음 모든 내용이 완벽하면 내 바닥 글 내용이 사라집니다. 이 코드의 문제점이나 내가 잘못하고있는 부분을 알고 싶습니다.
에 선
을 수정합니다. – jamesbar2