System.Web.UI.Control.ResolveUrl C# (CSharp) Method

ResolveUrl() public method

public ResolveUrl ( string relativeUrl ) : string
relativeUrl string
return string
		public string ResolveUrl (string relativeUrl)
		{
			if (relativeUrl == null)
				throw new ArgumentNullException ("relativeUrl");

			if (relativeUrl == String.Empty)
				return relativeUrl;

			if (VirtualPathUtility.IsAbsolute (relativeUrl))
				return relativeUrl;

			if (relativeUrl [0] == '#')
				return relativeUrl;

			string ts = AppRelativeTemplateSourceDirectory;
			HttpContext ctx = Context;
			HttpResponse resp = ctx != null ? ctx.Response : null;
			if (ts == null || ts.Length == 0 || resp == null || relativeUrl.IndexOf (':') >= 0)
				return relativeUrl;
			
			if (!VirtualPathUtility.IsAppRelative (relativeUrl))
				relativeUrl = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (ts), relativeUrl);
			
			return resp.ApplyAppPathModifier (relativeUrl);
		}

Usage Example

 /// <summary>
 /// Simplified Helper function that is used to add script files to the page
 /// This version adds scripts to the top of the page in the 'normal' position
 /// immediately following the form tag.
 /// </summary>
 /// <param name="script"></param>
 public static void IncludeScriptFile(Control control, string scriptFile)
 {
     scriptFile = control.ResolveUrl(scriptFile);
     ClientScriptProxy.ClientScriptProxy.Current.RegisterClientScriptInclude(control, typeof(ControlResources),
                                   Path.GetFileName(scriptFile).ToLower(),
                                   scriptFile);
 }
All Usage Examples Of System.Web.UI.Control::ResolveUrl