读取字符串作为HTML

时间:2016-04-18 13:03:03

标签: c# wpf visual-studio

我一直在寻找,但我无法找到有助于我的信息。
我有这个字符串变量,其中包含一堆HTML(标签,文本和图像链接),我想知道如何将该字符串转换为某种HTML支持的类型,以显示在我的应用程序中,以便它出现图像和文本以粗体显示,而不仅仅是带有标记的纯文本。

<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
  <td colspan="3">
    <h2>
      <img src="https://www.iseg.ulisboa.pt/aquila/getFile.do?method=getFile&amp;fileId=682501" alt="" width="745" height="497" />
    </h2>
  </td>
</tr>
<tr>
  <td colspan="3">
    <table border="0" cellspacing="0" cellpadding="0">
      <tbody>
        <tr>
          <td>
            <h3>
            <a href="https://onedrive.live.com/redir?resid=21016A3C1649D3A2!4589&amp;authkey=!ACVZ-u-igsIFDLs&amp;ithint=folder%2cjpg">&gt;&nbsp;Reportagem Fotográfica (7 de Março)</a>
            <br /> 
            <a href="https://onedrive.live.com/redir?resid=21016A3C1649D3A2!4738&amp;authkey=!AJbBcUJpWxqtP3g&amp;ithint=folder%2cjpg">&gt; Reportagem Fotográfica (9 de Março)</a></h3>
          </td>
        </tr>
        <tr>
          <td>
            <h6>Decorrem nos dias 7 e 9 de Março as Cerimónias de Entrega de Diplomas de Pós-Graduação, no Auditório CGD.
            <br />Contaram com momentos musicais de Manuel Rebelo e João Gil. Mais uma vez, parabéns a todos os diplomados!</h6>
            <h6>&nbsp;</h6>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
          </td>
        </tr>
      </tbody>
    </table>
  </td>
</tr>
 </tbody>
</table>

1 个答案:

答案 0 :(得分:2)

您可以使用WebBrowser控件来处理此问题,然后通过StoreLocatorController : UmbracoAuthorizedApiController // this allows only logged in users to call the api and also ensures that the correct umbraco context is set { public string basePath; public StoreLocatorController() { this.basePath = System.Web.Hosting.HostingEnvironment.MapPath(@"/App_Data/storeLocatorUpload/"); } [HttpPost] public void Go() { var myContext = Request.TryGetHttpContext(); if (myContext.Success) { HttpPostedFileBase myFile = myContext.Result.Request.Files["file"]; if (myFile == null) { throw new HttpException("invalid file"); } // save the file myFile.SaveAs(this.basePath + "file.ext"); UmbracoDatabase db = ApplicationContext.DatabaseContext.Database; // parse the data and insert them using UmbracoDatabase db //.. } } } 方法将其内容显式设置为HTML字符串:

NavigateToString()

如果这不能满足您的需求,您可以使用第三方控件,例如this HtmlRenderer available via NuGet,这听起来可能正是您所寻找的。