Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / QueryStringHandler.cs / 1305376 / QueryStringHandler.cs
using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; using System.Text; using System.Web.Resources; namespace System.Web.DynamicData { internal static class QueryStringHandler { public static string AddFiltersToPath(string virtualPath, IDictionaryfilters) { if (String.IsNullOrEmpty(virtualPath)) throw new ArgumentException( String.Format(CultureInfo.CurrentCulture, DynamicDataResources.QueryStringHandler_VirtualPathCannotBeEmpty), "virtualPath"); if (filters == null) throw new ArgumentNullException("filters"); string queryString = ConcatenateQueryStringElements(filters); if (String.IsNullOrEmpty(queryString)) return virtualPath; StringBuilder result = new StringBuilder(virtualPath); if (!virtualPath.Contains("?")) { result.Append('?'); } else { if (!virtualPath.EndsWith("?", StringComparison.Ordinal) && !virtualPath.EndsWith("&", StringComparison.Ordinal)) { result.Append('&'); } } result.Append(queryString); return result.ToString(); } private static string ConcatenateQueryStringElements(IDictionary parameters) { if (parameters.Count == 0) { return String.Empty; } StringBuilder result = new StringBuilder(); bool firstParam = true; foreach (String s in parameters.Keys) { if (!String.IsNullOrEmpty(s)) { string key = SanitizeParameterComponent(s); string value = SanitizeParameterComponent(parameters[s]); if (firstParam) firstParam = false; else result.Append('&'); result.Append(key); result.Append('='); result.Append(value); } } return result.ToString(); } private static string SanitizeParameterComponent(object value) { if (value == null) return String.Empty; string strValue = value.ToString(); // Trim trailing spaces, as they are typically meaningless, and make the url look ugly strValue = strValue.TrimEnd(); return Uri.EscapeDataString(strValue); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SmtpNtlmAuthenticationModule.cs
- FixedSOMTable.cs
- GeometryConverter.cs
- ComAdminWrapper.cs
- AssociationEndMember.cs
- WebControlsSection.cs
- FixedSOMTable.cs
- LayoutInformation.cs
- XsltLoader.cs
- CollectionContainer.cs
- ClientCultureInfo.cs
- SmtpFailedRecipientsException.cs
- CustomAssemblyResolver.cs
- WindowsButton.cs
- SqlDataSourceView.cs
- MetadataItemCollectionFactory.cs
- JournalNavigationScope.cs
- NamedPipeHostedTransportConfiguration.cs
- UInt16Converter.cs
- X509SecurityTokenProvider.cs
- HandlerBase.cs
- QilChoice.cs
- TcpHostedTransportConfiguration.cs
- MemoryFailPoint.cs
- HealthMonitoringSectionHelper.cs
- FontNameConverter.cs
- ResolveNameEventArgs.cs
- SystemIPv6InterfaceProperties.cs
- WorkflowMarkupSerializerMapping.cs
- HttpApplication.cs
- LicenseContext.cs
- Location.cs
- AttributeEmitter.cs
- DbProviderConfigurationHandler.cs
- WindowsGraphics2.cs
- CultureInfoConverter.cs
- SchemaInfo.cs
- SelectionService.cs
- ByteStreamMessageEncodingElement.cs
- validation.cs
- DefaultValueTypeConverter.cs
- CellCreator.cs
- SafeSecurityHandles.cs
- Function.cs
- SplineKeyFrames.cs
- CompositeScriptReferenceEventArgs.cs
- KeyMatchBuilder.cs
- GroupDescription.cs
- SchemaAttDef.cs
- EventlogProvider.cs
- PrintDialog.cs
- NumberSubstitution.cs
- TransactionFlowElement.cs
- Parameter.cs
- LinqDataSource.cs
- XPathDocument.cs
- Vector3D.cs
- AddDataControlFieldDialog.cs
- ApplicationInfo.cs
- webproxy.cs
- SupportsEventValidationAttribute.cs
- TextElementEnumerator.cs
- RefreshEventArgs.cs
- DomainConstraint.cs
- ListBindingConverter.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- ServiceMemoryGates.cs
- FormClosedEvent.cs
- PersonalizableAttribute.cs
- RuleRefElement.cs
- GradientStop.cs
- NotifyParentPropertyAttribute.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- ServiceObjectContainer.cs
- FollowerQueueCreator.cs
- CookieParameter.cs
- ListViewAutomationPeer.cs
- MSAAWinEventWrap.cs
- BooleanProjectedSlot.cs
- COM2ExtendedUITypeEditor.cs
- BeginStoryboard.cs
- RIPEMD160Managed.cs
- HttpCacheParams.cs
- TextServicesContext.cs
- TimeStampChecker.cs
- HtmlCommandAdapter.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- DataGridViewCellLinkedList.cs
- ReferencedType.cs
- followingquery.cs
- RequestCacheManager.cs
- DeferredSelectedIndexReference.cs
- ControlBindingsCollection.cs
- MenuItemStyleCollection.cs
- AudioException.cs
- Invariant.cs
- HyperLinkColumn.cs
- PropertyMappingExceptionEventArgs.cs
- InternalReceiveMessage.cs
- LinkGrep.cs