Search code examples
c#visual-studio-2005mshtmlsetattribute

No overload for method 'setAttribute' takes '2' arguments


I'm having trouble to set a new attribute to the element, VS 2005 returns me the following error on the code below:

Error 1 No overload for method 'setAttribute' takes '2 'arguments Error 2 No overload for method 'setAttribute' takes '2 'arguments Error 3 No overload for method 'setAttribute' takes '2 'arguments

some of what can be the problem?

Thank you!

try
{
   IHTMLElementCollection AllElements = document.all;
   foreach (IHTMLElement Element in AllElements)
   {                   
      if (Element.tagName.ToUpper() == "IMG")
      {   
         if (Element.offsetHeight <= 40 && Element.offsetHeight >= 20)
         {
            if (Element.offsetWidth <= 160 && Element.offsetWidth >= 130)
            {
               Element.setAttribute("width", Element.offsetWidth);
               Element.setAttribute("height", Element.offsetHeight);
               Element.setAttribute("src", "images/newimage.png");
            }
         }
      }
   }            
}   
catch (Exception e)
{
   string erro = e.Message;
   System.Windows.Forms.MessageBox.Show(erro);
}

Solution

  • From MSDN: it appears that the third argument should be optional.

    lFlags [in, optional] Type: long

    LONG that specifies whether to use a case-sensitive search to locate the attribute. Can be one of the following values:

    1

    The case of strAttributeName is respected.

    0

    Match strAttributeName regardless of case.

    You could try passing in 0 or 1.

    Element.setAttribute("width", Element.offsetWidth, 0);
    Element.setAttribute("height", Element.offsetHeight, 0);
    Element.setAttribute("src", "images/newimage.png", 0);
    

    Adding info from Hans' comment above (as suggested below):

    "VS2005 is stone cold old. C# v2 did not support optional arguments yet. " - Hans Passant :)