C sharp - Error CS0104: "HtmlElement" "System.Web.UI.HtmlControls.HtmlElement" y "System.Windows.Forms.Ht

 
Vista:

Error CS0104: "HtmlElement" "System.Web.UI.HtmlControls.HtmlElement" y "System.Windows.Forms.Ht

Publicado por Black_scorpion (5 intervenciones) el 18/04/2018 21:01:15
Hola estimados me encuentro desarrollado aplicación obtiene el DOM de un sitio web, el cual saque el contenido en primer instancia en WinForms y ahora me encuentro tratando de implementar lo mismo que realice WinForms a un WebForm en C#.
1.- La página a la cual estoy recorriendo del DOM con C# tiene varios IFRAME el código HML del sitio Web
2.- Dentro del código de C# necesitaba leer el contenido que se encontraba dentro del IFRAME con el id=A4, Dentro de Iframe.
3.- Dentro del IFRAME con el id A4 este contienes varios Select anidados con Ajax donde, como señale anteriormente tengo problemas para leer.
4.- El problema es el siguiente tratao de leer los select que se encuentra dentro del iframe A4 lo cual lo realizo en le WinForm pero cuando trato de adaptar el código al WebForm me aparece el siguiente problema

Mensaje de error del compilador: CS0104: 'HtmlElement' es una referencia ambigua entre 'System.Web.UI.HtmlControls.HtmlElement' y 'System.Windows.Forms.HtmlElement'
El código HTML es el siguiente :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<body>
<div id="contFrameUno" class="frameWrapper" style="margin: 0px auto; width: 100%;">
<div id="contFrameDos" class="frameWrapper" style="margin: 0px auto; width: 100%;">
<iframe id="a1" width="100%" height="103px" frameborder="0" style="vertical-align:top;" scrolling="no" src="top.php" name="a1">
<br>
<iframe id="a3" width="16%" height="730px" frameborder="0" style="vertical-align:top; margin-left: 28px;" scrolling="no" src="left.php" name="a3">
<iframe id="a4" width="78%" height="770px" frameborder="0" style="vertical-align:top;" scrolling="auto" src="moduloautoconsulta.php" name="a4">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="200" border="1">
  <tr>
    <td>
      <label for="Competencia"></label>
      <select name="Competencia" id="Competencia">
        <option value="A1">Competencia1</option>
        <option value="A2">Competencia2</option>
        <option value="A3">Competencia3</option>
      </select>
    </td>
  </tr>
  <tr>
    <td><select name="Tribunal" id="Tribunal">
        <option value="TR1">Tribunal 1</option>
        <option value="TR2">Tribunal 2</option>
        <option value="TR2">Tribunal 3</option>
    </select></td>
  </tr>
  <tr>
    <td><select name="Corte" id="Corte">
        <option value="Corte1">Corte 1</option>
        <option value="Corte2">Corte 3</option>
        <option value="Corte3">Corte 3</option>
    </select></td>
  </tr>
  <tr>
    <td><select name="Tipo" id="Tipo">
        <option value="Tipo1">Tipo 1</option>
        <option value="Tipo2">Tipo 2</option>
        <option value="Tipo4">Tipo 3</option>
    </select></td>
  </tr>
  <tr>
    <td><select name="SubTipo" id="SubTipo">
        <option value="SubT1">Sub Tipo 1</option>
        <option value="SubT2">Sub Tipo 2</option>
        <option value="SubT3">Sub Tipo 3</option>
    </select></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
</iframe>
<br>
<iframe id="a6" width="100%" height="83px" frameborder="0" style="vertical-align:bottom;" scrolling="no" src="footer.php" name="a6">
</div>
</div>


El Codigo de C# es el siguiente

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
private void GetLinksFromFrames()
{
    try
    {
 
        WebBrowser.Navigate("https://misitio.com/frameInv.php");
        string frameUrl;
 
        if (!(this.webPoderJudicial.Document == null))
        {
          //  WebCargado = true;
            HtmlWindow currentWindow = this.WebBrowser.Document.Window;
            if (currentWindow.Frames.Count > 0)
            {
                foreach (HtmlWindow frame in currentWindow.Frames)
                {
                    frameUrl = frame.Url.ToString();
 
                    if (frameUrl == "https:///misitio.com/moduloautoconsulta.php")
                    {
                         HtmlElementCollection select = frame.Document.GetElementsByTagName("select");
                        foreach (HtmlElement el in select)
                        {
 
                            if (el.Name == "competencia")
                            {
                                Application.DoEvents();
                                foreach (HtmlElement ele in el.GetElementsByTagName("option"))
                                {
                                    cmbCompetencia.Items.Add(ele.InnerText);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    catch (Exception ex) {
    }
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 373
Plata
Ha aumentado su posición en 2 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

Error CS0104: "HtmlElement" "System.Web.UI.HtmlControls.HtmlElement" y "System.Windows.Forms.Ht

Publicado por Agustin (171 intervenciones) el 19/04/2018 22:15:19
vayamos acostumbrandonos a usar var que C# no es java gracias a Dios....

1
foreach (var xxx in yyy)

y te evitas ese problema y otros mas.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Error CS0104: "HtmlElement" "System.Web.UI.HtmlControls.HtmlElement" y "System.Windows.Forms.Ht

Publicado por Black_scorpion (5 intervenciones) el 21/04/2018 23:22:08
Estimado hice el siguiente ejemplo cambie pero no me encuentra el contenido de los Iframe en este caso estoy tratando de extraer el contenido del iframe a4. No obtengo el contenido del los elementos por ejemplo :

1.- Competencia
2.- Corte
3.- Tribunal
4.- Tipo Busqueda

Realizo un debug del código y metodo GetLisksFromFrame2 no encuentra los elementos del select ya que quiero emplear este codigo en formulario asp.net C#

HtmlElementCollection select = iframe.Document.GetElementsByTagName("select");


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
private void GetLinksFromFrames2()
{
    try
    {
 
        // Hashtable linksTable = new Hashtable();
        string frameUrl;
 
        if (!(this.webPoderJudicial.Document == null))
        {
            //  WebCargado = true;
            HtmlWindow currentWindow = this.webPoderJudicial.Document.Window;
            HtmlElementCollection frames = this.webPoderJudicial.Document.GetElementsByTagName("iframe");
            foreach (HtmlElement iframe in frames)
            {
                Console.Write("Iframe  Contenedor" + iframe.Name + "\n\r");
                if (iframe.Name == "a4")
                {
                    HtmlElementCollection select = iframe.Document.GetElementsByTagName("select");
                    foreach (HtmlElement el in select)
                    {
 
                        if (el.Name == "competencia")
                        {
                            Application.DoEvents();
                            foreach (HtmlElement ele in el.GetElementsByTagName("option"))
                            {
                                cmbCompetencia.Items.Add(ele.InnerText);
                            }
                        }
                    }
 
                }
            }
        }
    }
    catch (Exception ex)
    {
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar