views:

55

answers:

1

I currently have a file "abc.htm" in my Custom Server Control Project and it's Build Action is set to Embedded Resource.

Now in the RenderContents(HtmlTextWriter output) method, I need to read that file and render it on the website.

I am trying the following but it's to no avail:

protected override void RenderContents(HtmlTextWriter output)
{
    var providersURL = Page.ClientScript.GetWebResourceUrl(typeof (OpenIDSel), "OpenIDSelector.Providers.htm");
    var fi = new FileInfo(providersURL); // <- exception here

    //the remaining code is to possibly render the file
}

This is an example of how the providersURL is:

/WebResource.axd?d=kyU2OiYu6lwshLH4pRUCUmG-pzI4xDC1ii9u032IPWwUzMsFzFHzL3veInwslz8Y0&t=634056587753507131

FileInfo is throwing System.ArgumentException: Illegal characters in path.

+1  A: 

You could do something like :

protected override void RenderContents(HtmlTextWriter output)
{

 var source = ReadEmbeddedResource("AssemblyName", "OpenIDSelector.Providers.htm");    

 //the remaining code is to possibly render the file

}


private string ReadEmbeddedResource(string assemblyName, string resouceName)
{
    var assembly = Assembly.Load(assemblyName);
    using (var stream = assembly.GetManifestResourceStream(resouceName))
    using(var reader = new StreamReader(stream))
    {
        return reader.ReadToEnd();
    }
}
Matt Dearing