VB.NET || How To Add, Update & Remove Values From A URL Query String Using VB.NET

Print Friendly, PDF & Email

The following is a module with functions which demonstrates how to add, update and remove parameters from a query string using VB.NET.

The following functions use System.Web to modify the url.

Note: To use the functions in this module, make sure you have a reference to ‘System.Web‘ in your project.

One way to do this is, in your Solution Explorer (where all the files are shown with your project), right click the ‘References‘ folder, click ‘Add Reference‘, then type ‘System.Web‘ in the search box, and add the reference titled System.Web in the results Tab.


1. Add & Update – Single Parameter

The example below demonstrates the use of ‘Utils.Http.AddParameter‘ to add a query string parameter to a url.

This function will add the parameter if it does not exists. Or it will update the parameter if it does.


2. Add & Update – Multiple Parameters

The example below demonstrates the use of ‘Utils.Http.AddParameter‘ to add a query string parameter to a url.

This function will add the parameter if it does not exists. Or it will update the parameter if it does.


3. Remove – Single Parameter

The example below demonstrates the use of ‘Utils.Http.RemoveParameter‘ to remove a query string parameter from a url.


4. Remove – Multiple Parameters

The example below demonstrates the use of ‘Utils.Http.RemoveParameter‘ to remove multiple query string parameters from a url.


5. Clear – Remove All Parameters

The example below demonstrates the use of ‘Utils.Http.ClearParameters‘ to remove all query string parameters from a url.


6. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


7. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Leave a Reply