SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a few HTML files which I intend to use as either email templates or schemas.

When I run this code:

var t = "Not found!";
        SPSecurity.RunWithElevatedPrivileges(() =>
             using (var site = new SPSite(spSite.ID))
                 var web = site.RootWeb;
                 var file = web.GetFile("/_layouts/email/" + template + ".html");
                 t = Encoding.Default.GetString(file.OpenBinary());
        return t;

my method returns this error: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Is it not possible to get files from /_layouts/ when not logged in?

share|improve this question
up vote 1 down vote accepted

While I'm not 100% certain, I suspect that your problem is that you are using a SharePoint-specific method to access a file that is not actually in SharePoint. Everything in /_layouts/ is actually in the underlying file system of the server.

What might work better on a lot of fronts is to move your templates into Sharepoint, either in their own document library or under /Style Library/ somewhere. Not only would that make your method above work, but it would also ensure that any updates to the templates would be reflected across the farm, without having to copy the html files manually.

Just a thought.

share|improve this answer

Use var spTemplatePath = SPUtility.GetGenericSetupPath(@"TEMPLATE\LAYOUTS\email\" + template + ".html"); to get the path on the the filesystem, and then just open a filestream.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.