We have a team site in our solution (SPS 2010 - Enterprise). On this site there's a list. For every new item in the list, it creates a new site from a template.
Structure:
- team-website
- website 1
- website 2
- ...
On the template for these sites there is (among other elements) a document library with a single Excel file (.xlsx) and a Chart Web Part. The data source of the Chart Web Part is the Excel file (using Excel Services).
The source for the web part can be set without much hassle and it works as it should. But, since the template is used for these various websites, this isn't a working solution and I haven't figured out a way to set the URL relatively on the web part.
A logical solution for me was to add a new web part to my Visual Studio project, that derives from ChartWebPart. I checked MSDN and found the WorkBookUrl member and overrode the OnInit() method:
protected override void OnInit(EventArgs e)
{
string excelFile = SPContext.Current.Web.ServerRelativeUrl
+ "/Dokumente/siteSheet.xlsx";
this.WorkBookUrl = excelFile;
}
Then I did a test, and it worked like a charm. After that, I made some last changes on the chart's design and saved the site as a template. From this template I created a site and... no Chart Web Part. (It is definitely there, since the debugger jumps in on the breakpoint I set in the OnInit method, but I can't see it!)
I don't know what's the problem here. Either my code doesn't work in the end or it's something else. I tried some other things too, like editing the DataBindingString, nothing worked.
EDIT: I tried using a list instead, and it worked fine. That still doesn't answer my question of why it doesn't work with the WorkBookUrl though.