Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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# 使用mshtml不会';行不通_C#_Mshtml - Fatal编程技术网

C# 使用mshtml不会';行不通

C# 使用mshtml不会';行不通,c#,mshtml,C#,Mshtml,我有一个c#应用程序,我尝试过使用一些mshtml元素。但我有个问题。使用mshtml的命名空间给我一个错误是Visual Studio 2012 这是我的源代码 namespace Tagger { using mshtml; using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices;

我有一个c#应用程序,我尝试过使用一些mshtml元素。但我有个问题。使用mshtml的
命名空间给我一个错误是Visual Studio 2012

这是我的源代码

namespace Tagger
{

    using mshtml;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Text;

    public class HTMLForm
    {
        private string _action = "";
        private string _method = "";
        public Hashtable Inputs = new Hashtable();

        public HTMLForm(IHTMLFormElement element)
        {
            this._method = element.method;
            this._action = element.action;
            foreach (IHTMLInputElement element2 in (IHTMLElementCollection) element.tags("input"))
            {
                try
                {
                    string name = element2.name;
                    string str2 = element2.value;
                    if (name == null)
                    {
                        name = element2.type;
                    }
                    this.Inputs.Add(name, str2);
                }
                catch
                {
                }
            }
        }

        public static HTMLForm[] GetAllForms(string html)
        {
            List<HTMLForm> list = new List<HTMLForm>();
            HTMLDocument document = (HTMLDocument) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("25336920-03F9-11CF-8FD0-00AA00686F13")));
            document.write(new object[] { html });
            document.close();
            foreach (IHTMLFormElement element in document.forms)
            {
                list.Add(new HTMLForm(element));
            }
            return list.ToArray();
        }

        public static HTMLForm GetFormByAction(string html, string action)
        {
            foreach (HTMLForm form in GetAllForms(html))
            {
                if (form.Action.ToLower() == action.ToLower())
                {
                    return form;
                }
            }
            return null;
        }

        public string ToPostData()
        {
            StringBuilder builder = new StringBuilder();
            foreach (string str in this.Inputs.Keys)
            {
                object obj2 = this.Inputs[str];
                string str2 = (obj2 == null) ? "" : obj2.ToString();
                builder.AppendFormat("{0}={1}&", HTTPBase.encode(str), HTTPBase.encode(str2));
            }
            if (builder.Length > 1)
            {
                return builder.ToString().Substring(0, builder.Length - 1);
            }
            return "";
        }

        public string Action
        {
            get
            {
                return this._action;
            }
            set
            {
                this._action = value;
            }
        }

        public string Method
        {
            get
            {
                return this._method;
            }
            set
            {
                this._method = value;
            }
        }        
    }
}
是否缺少using指令或程序集引用

错误2找不到类型或命名空间名称“IHTMLFormElement”(是否为 缺少使用指令或程序集引用?)

错误3找不到类型或命名空间名称“IHTMLElementCollection”(是否缺少using指令或程序集引用?)

错误4找不到类型或命名空间名称“HTMLDocument”(是否缺少using指令或程序集引用?)


右键单击
解决方案资源管理器中项目中的
引用
。然后单击添加引用…
。在
Assemblies
中键入搜索“HTML”,您将看到
Microsoft.mshtml
。将此添加到项目中,您可以使用HTMLDocument。祝您好运

Microsoft.mshtml位于引用管理器的COM选项卡中,它的名称为“Microsoft HTML对象库”。

我想补充一点,我们曾多次遇到问题,即所需的名称空间从mshtml切换到mshtml,然后再切换回来。因此,即使添加了引用并且所有内容看起来都很好,也要检查名称空间是否由于更新了库而发生了更改。

mshtml已更改为mshtml。 所以在你这么做之后:

Microsoft.mshtml位于引用管理器的COM选项卡中,它的名称为“Microsoft HTML对象库”


将代码中的mshtml更改为mshtml。

它是否正确显示在项目引用中?这是唯一的错误吗?我已在我的计算机中安装了windows 8 4.5.0 sdk,我还在线下载了一个mshtml.dll并将其添加到VS中。但我仍然收到错误。这是我在该脚本中遇到的唯一错误。您需要添加对Microsoft HTML对象库的COM引用。就我个人而言,我只使用标准方式(无COM组件)添加了对mshtml的引用,并且成功了。删除对本地mshtml.dll的引用,并在添加引用中搜索mshtmldialog@idlerboris我也有同样的问题。打开“添加引用…”,单击程序集,在搜索中键入“html”,并显示“未找到任何项目”。搜索
mshtml
,您将获得两个选项,第一个选项工作正常。
Error 5   The type or namespace name 'HTMLDocument' could not be found (are