user3802347
user3802347

Reputation: 108

Reading ViewState Value from Raw HTML

I have an web application where I am using webClient.UploadData(url, "POST", bytes) to load data to a URL. The response that I am getting back is an HTML response. I’ve been able to get the Value using Regex.Split function. However, I’d like to know if there is a better way to get the result from the html file. Here is an example of the html file that is returned to me.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<head><title>
</title></head>
<body>
    <form method="post" action="mydomain.com/users/username=user1&password=password" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=

     "The data that I want"

       />
      <div>
        <br />
        <br />
        <br />
        <br />

    </div>
    </form>
</body>
</html>

Updated 08/01/2014 :

I tried it using XElement, and the node was null.

var nodes = from x in element.Nodes()
                        where x.NodeType == XmlNodeType.Text
                        select (XText)x;

            foreach (var val in nodes)
            {
                string st = val.Value;
            }

I was using XElement the wrong way. I was supposed to look for DescendantNodes instead of just nodes. I siwtched the above code, and I was able to extract the data.

Upvotes: 0

Views: 569

Answers (1)

Matan Wiesner
Matan Wiesner

Reputation: 186

If this xhtml page I recommend do it with class for reading xml, like XElement

Upvotes: 1

Related Questions