I am making this if statement and inside i am setting this SPWebTemplate which is a type. I think it would work fine, but it says that it does not exist in the current context. if (properties.WebUrl == "http://sharepointdev") { SPWebTemplate spWebTemplate = oWebsite.Site.GetWebTemplates(1030)["{378B494F-F38C-4F07-8D25-CA50E64C209F}#TemplateKSI"]; } else { SPWebTemplate spWebTemplate = oWebsite.Site.GetWebTemplates(1030)["{5FC51B7F-355E-431F-9C65-3663590346F4}#Sag"]; } > The name 'spWebTemplate' does not exist in the current context How can that be? And it does not help setting the variable before like SPWebTemplate spWebTemplate; if(... It then says: > A local variable named 'spWebTemplate' cannot be declared in this > scope because it would give a different meaning to 'spWebTemplate', > which is already used in a 'parent or current' scope to denote > something else. but this example works fine: long websiteid; if (properties.ListItem["LP_SagsID"] == null) { websiteid = long.Parse(properties.ListItemId.ToString()) + startnumber; } else { websiteid = long.Parse(properties.ListItem["LP_SagsID"].ToString()); }