473,473 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cQueryString Class to resolve Read Only problem

Ok... I've mooched off this group for a while now. Time to give some
code back.

Here's a class I wrote to solve the problem of handling query strings.
I use it for an application where the page needs to preserve the
existing QueryString, but add or remove a couple items and then
redirect it back to the same page or other locations.

....A good example of how polymorphism can be useful for us VB'ers who
are less familiar with the concept.

-SF

Here's the class *****

Imports System.Collections.Specialized

Public Class cQueryString
Inherits NameValueCollection

Public Sub New(ByVal QueryString As NameValueCollection)

Dim i As Integer
With QueryString
'--Cycle through Items and Add them back
For i = 0 To .Count - 1
Me.Add(.GetKey(i), .Item(i))
Next
End With
End Sub

Public Overloads Sub Add(ByVal Name As String, ByVal Value As
String, ByVal Overwrite As Boolean)
If Name = "" Then Exit Sub

If Overwrite = True Then
Me.Remove(Name)
Me.Add(Name, Value)
Else
Me.Add(Name, Value)
End If
End Sub

Public Overrides Function ToString() As String
Dim i As Integer
Dim sbOutput As New System.Text.StringBuilder()

If Me.HasKeys = False Then
'--Return Blank String if Empty QueryString
Return ""
End If

sbOutput.Append("?")

With Me
'--Cycle through Items and Add them back
For i = 0 To .Count - 1
sbOutput.Append(.GetKey(i) & "=" & .Item(i))
If i <> .Count - 1 Then
sbOutput.Append("&")
End If
Next
End With

Return sbOutput.ToString
End Function

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
And here's how I use it in my code *****

Dim objQueryString As New cQueryString(Request.QueryString)

objQueryString.Add("SomeKey", "SomeValue", True)
objQueryString.Add("AnotherNeededKey", "AnotherValue", True)
objQueryString.Remove("NoLongerNeededKey")

Response.Redirect("http://www.weblocation.com/myweb" &
objQueryString.ToString)

Another way to use it *****
'-- It's just as easy to clear out all the strings, and add the ones
you want.
Dim objQueryString As New cQueryString(Request.QueryString)
objQueryString.Clear

'-- Just as easy to Add together at once,
'-- or intersperse throughout a procedure as stuff gets determined.
objQueryString.Add("FirstItem", "FirstItemValue", True)
objQueryString.Add("SecondItem", "SecondItemValue", True)
objQueryString.Add("ThirdItem", "ThirdItemValue", True)

Response.Redirect("http://www.weblocation.com/myweb" &
objQueryString.ToString)

'-- Hopefully a little more readible then piling stuff at the end
'-- of a redirect.
Nov 17 '05 #1
0 1431

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Aung | last post by:
Has anybody develop RFC1950 and RFC1951 compliant Zip utility? Any pointer will be appreciated.
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
9
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
0
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port...
16
by: Wayne Wengert | last post by:
I am using VS.NET 2003, VB.NET, ADO.NET and an Access 2000 database. I want to display a list of all tables in an Access database. I want to put that list of table names in a listbox so the user...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
8
by: =?Utf-8?B?TmFkYXY=?= | last post by:
Hi, I am using COM with RunningObjectTable, take in mind the following points: 1. I have a server that runs as a service this service register an object in ROT, the object should be accesible...
0
by: BrianKer | last post by:
Hi! It's my first discussion on this forum. First I have a exe like this below (the object can invoke by console) public class DynamicLoad { public Type AssemblyType = null; ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.