Skip to content

Instantly share code, notes, and snippets.

@davecowart
Created May 17, 2011 15:19
Show Gist options
  • Save davecowart/976670 to your computer and use it in GitHub Desktop.
Save davecowart/976670 to your computer and use it in GitHub Desktop.
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);
}
@davecowart
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment