Have you come across a situation, where you set the query parameters, but want to check for null values, and then URL encode the value, heres a function that can be added to a common utilities class that can be called from your application to URL Encode the value, if null empty string is returned.
''' -----------------------------------------------------------------------------
''' <summary>
''' URL Encode the object
''' </summary>
''' <param name="value"></param>
''' <returns>URL Encoded string>/returns>
''' <remarks>
''' </remarks>
''' <history>
''' [K. Gopi] 8/25/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function URLEncode(ByVal value As Object) As String
Try
If (value Is Nothing) OrElse (value Is DBNull.Value) Then
Return String.Empty
Else
Return Web.HttpUtility.UrlEncode(Convert.ToString(value))
End If
Catch
Return String.Empty
End Try
End Function
No comments:
Post a Comment