Code:
/ 4.0 / 4.0 / 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. 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, IDictionary filters) { 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
- Polyline.cs
- XmlBinaryWriterSession.cs
- InheritanceAttribute.cs
- XslUrlEditor.cs
- IdentityManager.cs
- CacheVirtualItemsEvent.cs
- CollectionsUtil.cs
- xmlfixedPageInfo.cs
- UrlMappingsSection.cs
- CodeSubDirectoriesCollection.cs
- AuthenticationModulesSection.cs
- AttachedPropertyMethodSelector.cs
- SQLRoleProvider.cs
- DesignBindingEditor.cs
- WindowsNonControl.cs
- NativeCppClassAttribute.cs
- AssertUtility.cs
- DbException.cs
- OleDbEnumerator.cs
- securestring.cs
- EmptyControlCollection.cs
- ExpressionPrefixAttribute.cs
- ResourceProviderFactory.cs
- UnsafeNetInfoNativeMethods.cs
- TableColumn.cs
- EntityDataSourceValidationException.cs
- Tile.cs
- VBIdentifierName.cs
- ColorAnimationBase.cs
- WmpBitmapDecoder.cs
- User.cs
- UiaCoreTypesApi.cs
- EntityDescriptor.cs
- BigInt.cs
- OpenFileDialog.cs
- ListBoxDesigner.cs
- DataPagerCommandEventArgs.cs
- SecurityContext.cs
- XmlDataSource.cs
- StoryFragments.cs
- CodeSnippetExpression.cs
- TypedRowHandler.cs
- AddDataControlFieldDialog.cs
- ZipFileInfo.cs
- ViewSimplifier.cs
- PhysicalOps.cs
- SHA256Managed.cs
- SimpleWorkerRequest.cs
- TextTreeTextElementNode.cs
- __ComObject.cs
- ControlAdapter.cs
- XPathItem.cs
- HyperLinkColumn.cs
- SkewTransform.cs
- ClosableStream.cs
- EntityDescriptor.cs
- UITypeEditor.cs
- HandlerFactoryCache.cs
- ISAPIRuntime.cs
- DataContractJsonSerializerOperationBehavior.cs
- RequestQueue.cs
- PointLight.cs
- BuildProvider.cs
- SolidColorBrush.cs
- StorageAssociationTypeMapping.cs
- X509ChainPolicy.cs
- DesignBindingPicker.cs
- PageAsyncTaskManager.cs
- EngineSiteSapi.cs
- ButtonRenderer.cs
- DataGridColumnCollection.cs
- ExpandedProjectionNode.cs
- DataKeyArray.cs
- InstancePersistenceException.cs
- CapiNative.cs
- WebRequestModulesSection.cs
- ResourceCodeDomSerializer.cs
- RegexCompiler.cs
- SqlGenericUtil.cs
- HtmlSelectionListAdapter.cs
- PropertyChangedEventManager.cs
- NaturalLanguageHyphenator.cs
- AnnotationHelper.cs
- XMLSchema.cs
- ListViewAutomationPeer.cs
- XmlSchemaSequence.cs
- PhysicalFontFamily.cs
- FixedSOMSemanticBox.cs
- DrawingContextWalker.cs
- ReliabilityContractAttribute.cs
- IsolatedStorageFileStream.cs
- SiteMapNodeCollection.cs
- HashSet.cs
- SiteMapDataSource.cs
- DbInsertCommandTree.cs
- SqlOuterApplyReducer.cs
- AdapterUtil.cs
- BoolExpression.cs
- IndexedString.cs
- PropertyInformation.cs