Created
May 17, 2011 15:19
-
-
Save davecowart/976670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var file = new System.IO.StreamReader(script)) { | |
var fileContent = file.ReadToEnd(); | |
if (scriptType == ScriptType.Stylesheet) { | |
var fromUri = new Uri(context.Server.MapPath("~/")); | |
var toUri = new Uri(new FileInfo(script).DirectoryName); | |
var relativeUri = fromUri.MakeRelativeUri(toUri); | |
fileContent = fileContent.Replace("url(", "url(/" + relativeUri.ToString() + "/"); | |
} | |
scriptbody.Append(fileContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is from line 49 in https://github.com/davecowart/RazorScriptManager/blob/master/content/Handlers/RazorScriptManager.cs . This will effectively wrap the entire statement in a try/finally block, and call .Dispose() on file in the finally. Only works with objects that implement IDisposable.
More info on using: http://msdn.microsoft.com/en-us/library/yh598w02(v=VS.100).aspx