Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / Util / UrlPath.cs / 1 / UrlPath.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.Util {
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI.Design;
///
/// Helper class for URLs.
/// The only method in this class is borrowed directly from the runtime's
/// System.Web.Util.UrlPath class.
///
internal class UrlPath {
// Only static methods, so hide constructor.
private UrlPath() {
}
///
/// Returns true if the path is an absolute physical path.
///
private static bool IsAbsolutePhysicalPath(string path) {
if (path == null || path.Length < 3)
return false;
if (path.StartsWith("\\\\", StringComparison.Ordinal))
return true;
return (Char.IsLetter(path[0]) && path[1] == ':' && path[2] == '\\');
}
///
/// Maps an arbitrary path (physical absolute, app-relative, relative) to
/// a physical path using designer host services. If the path cannot be
/// mapped because certain services are not present, null is returned.
///
internal static string MapPath(IServiceProvider serviceProvider, string path) {
if (path.Length == 0) {
return null;
}
if (IsAbsolutePhysicalPath(path)) {
// Absolute path
return path;
}
else {
// Root relative path - use designer host service to map the path
WebFormsRootDesigner rootDesigner = null;
if (serviceProvider != null) {
IDesignerHost designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
if ((designerHost != null) && (designerHost.RootComponent != null)) {
rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as WebFormsRootDesigner;
if (rootDesigner != null) {
string resolvedUrl = rootDesigner.ResolveUrl(path);
// Use the WebApplication server to get a physical path from the app-relative path
IWebApplication webApplicationService = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));
if (webApplicationService != null) {
IProjectItem dataFileProjectItem = webApplicationService.GetProjectItemFromUrl(resolvedUrl);
if (dataFileProjectItem != null) {
return dataFileProjectItem.PhysicalPath;
}
}
}
}
}
}
// Could not get service to map path, return null
return null;
}
}
}
// 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
- RewritingPass.cs
- CodeAttributeDeclarationCollection.cs
- Input.cs
- PropertyDescriptorCollection.cs
- GenerateTemporaryTargetAssembly.cs
- Pair.cs
- DataColumnChangeEvent.cs
- SqlConnectionString.cs
- TransformPatternIdentifiers.cs
- X509Chain.cs
- CellParaClient.cs
- TypedElement.cs
- EventListenerClientSide.cs
- mansign.cs
- ClientTarget.cs
- TreeNodeConverter.cs
- IndicShape.cs
- SamlAuthorizationDecisionStatement.cs
- BuilderElements.cs
- IIS7WorkerRequest.cs
- XPathEmptyIterator.cs
- SafeArrayTypeMismatchException.cs
- ExpressionConverter.cs
- ThreadAttributes.cs
- configsystem.cs
- ExpressionPrefixAttribute.cs
- TransformerConfigurationWizardBase.cs
- XamlWriter.cs
- WebPartDisplayModeCollection.cs
- AstTree.cs
- TrailingSpaceComparer.cs
- AnonymousIdentificationModule.cs
- WebPart.cs
- XmlSchemaImport.cs
- AsymmetricSecurityBindingElement.cs
- XmlException.cs
- RC2.cs
- Zone.cs
- ProfileGroupSettingsCollection.cs
- BreakSafeBase.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- Publisher.cs
- SspiHelper.cs
- XmlSchemaNotation.cs
- MethodRental.cs
- FusionWrap.cs
- SendDesigner.xaml.cs
- MetricEntry.cs
- XmlEventCache.cs
- NetStream.cs
- UserControl.cs
- Directory.cs
- TypeGeneratedEventArgs.cs
- ListSortDescriptionCollection.cs
- PackWebRequestFactory.cs
- EncoderFallback.cs
- CollectionBuilder.cs
- QilVisitor.cs
- PersonalizationProviderCollection.cs
- TimeSpanOrInfiniteConverter.cs
- DetailsView.cs
- ResolveMatchesMessage11.cs
- DefaultParameterValueAttribute.cs
- JoinQueryOperator.cs
- CustomAttributeFormatException.cs
- WrappedIUnknown.cs
- MemoryRecordBuffer.cs
- RealProxy.cs
- SimpleWorkerRequest.cs
- TabControl.cs
- TdsParameterSetter.cs
- WorkflowServiceBehavior.cs
- GZipStream.cs
- CodeTypeMemberCollection.cs
- ScrollEventArgs.cs
- MostlySingletonList.cs
- ItemContainerPattern.cs
- CapabilitiesPattern.cs
- ContextMenu.cs
- DbModificationClause.cs
- _SingleItemRequestCache.cs
- PointAnimationUsingPath.cs
- ModelTreeEnumerator.cs
- LineBreak.cs
- TextFormatterImp.cs
- ContentControl.cs
- Utils.cs
- BitmapCacheBrush.cs
- NamespaceEmitter.cs
- WebZone.cs
- ServicesUtilities.cs
- LongValidator.cs
- X509Utils.cs
- ConfigXmlElement.cs
- DataGridViewLinkColumn.cs
- ImageMap.cs
- BatchServiceHost.cs
- StateChangeEvent.cs
- UnionCodeGroup.cs
- embossbitmapeffect.cs