1
<input name="chkFile" value="2062223616_7147073260_1440589192619132.WMA" type="checkbox">

from this code I want only the value data

Example:

2062223616_7147073260_1440589192619132.WMA

below my code not working so please help me.

My code

HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
            foreach (HtmlElement bEl in bColl)
            {
                if (bEl.GetAttribute("name").Equals("chkFile"))
                    showaudiourl.Text = bEl.OuterHtml.Split('"')[3];
            }
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63

2 Answers2

0

Use webBrowser2.GetAttribute("value") to get the value you want.

HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl) {
    if (bEl.GetAttribute("name").Equals("chkFile")) {
        showaudiourl.Text = bEl.GetAttribute("value");    //Changes here
    }
}
Shrinivas Shukla
  • 4,325
  • 2
  • 21
  • 33
0

All you need is add a piece of code telling the app to wait until the web browser document gets initialized:

webBrowser2.Navigate(@"C:\tmp.html");                        // Use your own URL here
while (webBrowser2.ReadyState != WebBrowserReadyState.Complete) // Without it, 
   Application.DoEvents();                                // the document will be null

HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl)
{
   if (bEl.GetAttribute("name").Equals("chkFile"))
      showaudiourl.Text = bEl.GetAttribute("value");
}

The value should be accessed with bEl.GetAttribute("value").

Alternatively, you could use a webBrowser2_DocumentCompleted event to process the HTML document there.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • And surely you do not need a regex. On SO, a lot of people would downvote your question if you ask to parse an HTML document with regex linking to [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/a/1732454/3832970) post. – Wiktor Stribiżew Aug 26 '15 at 14:32