Search code examples
c#windows-phone-8namespacesusing

HttpUtility.ParseQueryString and NameValueCollection in Windows Phone 8


I'm having some trouble using the HttpUtility.ParseQueryString(string) in a windows 8 app I'm just using this line

NameValueCollection coll = HttpUtility.ParseQueryString(result);

And the problem is that the parts "NameValueCollection" and "HttpUtility" are underlined in red, as if Visual Studio couldn't find them (that's what the error says) But I don't know which namespaces I should use !

I tried

using System.Collections.Specialized ; //for NamevalueCollection
using System.Web ; //for HttpUtility

For the first one, it doesn't seem to work as the import is successful but my "NameValueCollection" is still underlined and for the second one, VS considers it as an error and my "using" is underlined... Thanks


Solution

  • Got it working with this:

    using System.Collections.Specialized;
    using System.Web;
    
    namespace Test   
    {
        class Foo
        {
            public Foo()
            {
                NameValueCollection foo = HttpUtility.ParseQueryString("data");
            }
        }
    } 
    

    Make sure to reference the System.Web.dll and System.dll

    see:

    http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection%28v=vs.110%29.aspx

    and

    http://msdn.microsoft.com/en-us/library/ms150046%28v=vs.110%29.aspx

    UPDATE

    Since OP's question is about windows phone (which doesn't have System.Web), an alternative is found here:

    HttpUtility.ParseQueryString and NameValueCollection in Windows Phone 8