UrlEncode/System.Web not available in console application?
I need UrlEncode in my application because i am submitting a form to my server. My app is a quick console utility targeting to .NET 3.5.
The page says i need System.Web assembly, yet when i 开发者_如何学Pythontry to add the reference it isnt there. My WebServer application has it which is also targeted to 3.5 but this console app cant reference it. Why not? how can i access UrlEncode?
You can - just make sure you've added a reference to System.Web.dll, which may not be in a console project by default.
I suspect this isn't in the Client Profile, mind you - I don't know if that's an issue for you.
I've just tested this with a console app from the command line:
using System;
using System.Web;
class Test
{
static void Main()
{
string text = "hello there";
string encoded = HttpUtility.UrlEncode(text);
Console.WriteLine(encoded); // prints hello+there
}
}
I was able to just compile with
csc Test.cs
but I suspect the default response file contains more assembly references than the default Console Application project template in Visual Studio...
精彩评论