using runtime html4,c# - Using mshtml doesn't work - Stack Overflow

I have a c# app and i have tried using some mshtml elements. But i have a problem. The using mshtml; namespace gives me a error is Visual Studio 2012.

Here is my source code,

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 list = new List();

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;

}

}

}

}

But i can't use the functions of htmlelement, IHTMLElementCollection . The compiler gives me a error.

Error 1 The type or namespace name 'mshtml' could not be found (are

you missing a using directive or an assembly reference?)

Error 5 The type or namespace name 'HTMLDocument' could not be found (are

you missing a using directive or an assembly reference?

Error 2 The type or namespace name 'IHTMLFormElement' could not be found (are you

missing a using directive or an assembly reference?)

Error 3 The type or namespace name 'IHTMLElementCollection' could not be found (are you missing a using directive or an assembly reference?)

Error 4 The type or namespace name 'HTMLDocument' could not be found (are you missing a using directive or an assembly reference?)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值