简体   繁体   English

如何设置WebBrowser.DocumentType

[英]How to Set WebBrowser.DocumentType

我们如何设置WebBrowser.DocumentType?

The DocumentType property only reflects the documenttype of the current document. DocumentType属性仅反映当前文档的文档类型。

You'll have to modify the content of the web browser through the Document or DocumentText property. 您必须通过Document或DocumentText属性修改Web浏览器的内容。

Having checked it, the property actually only contains a rather uninteresting text description like "Text Document" or "JPEG Image". 选中该属性后,该属性实际上仅包含一个不太有趣的文本描述,例如“文本文档”或“ JPEG图像”。 Possibly not what you're after anyway. 无论如何,可能不是你想要的。

I did this by creating a temporary file, setting an appropriate file extension on that file, then loading that file. 为此,我创建了一个临时文件,在该文件上设置了适当的文件扩展名,然后加载该文件。 It seems like there should be an easier way, but this worked for me. 似乎应该有一种更简单的方法,但这对我有用。

            string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xml";
            File.WriteAllText(fileName, xmlTextBox.Text);
            webBrowser1.Url = new Uri(fileName);
            // The following seems like it would work, but the document type is wrong.  Typically
            // the window looks blank, but when you right click and ask it to show source, you
            // see the XML code.
            //webBrowser1.DocumentText = xmlTextBox.Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM