-1

I have just created an event receiver to ensure that my colour palette is activated on my 2013 Web application. The below code is what I have inside

public class SitePublishingResourcesEventReceiver : SPFeatureReceiver 

I keep getting the error Cannot resolve symbol 'GetFile'

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {

        // Get the SPColor file. Replace with the path to your SPColor file.
        SPFile colorPaletteFile = Web.GetFile("_catalogs/theme/15/ColorPalette.spcolor");
        if (null == colorPaletteFile || !colorPaletteFile.Exists)
        {
            // TODO: handle the error.
            return;
        }

I have googled to see if I'm missing usings or something, but I can't find anything

Thanks in advance for your help

  • 1
    Just an observation, why can't people give a reason as to why they vote a question down? Instead of hiding behind anonymity. Is this not the reason this site exists? – Scubacode Mar 2 '15 at 12:58
3

You might be using a wrong 'Web' object. It shouldn't be System.Web or Microsoft.Web. It should be from Microsoft.SharePoint.SPWeb namespace. So first of all you need to get an 'SPWeb' object from 'properties'. Depending on where you are activating the feature, it should be something like this:

If you are activating a Web scoped feature:

SPWeb web = properties.Feature.Parent as SPWeb;
SPFile colorPaletteFile = web.GetFile(@"_catalogs/theme/15/ColorPalette.spcolor");

If you are activating a Site scoped feature and want to get file from the root web:

SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
SPFile colorPaletteFile = web.GetFile(@"_catalogs/theme/15/ColorPalette.spcolor");

Of if you are activating a Web Application or a Farm scoped feature, then you need to get specific site first and then specific web.

Hope this helps.

  • My Hero! Thanks! It is indeed a Site feature. I added your second snippet there and it works like a charm! – Scubacode Mar 2 '15 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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