Thursday, January 19, 2012

SharePoint 2010 Sandbox Visual WebPart

When you use sandbox Visual Web Part and TemplateControl.LoadControl method is not working in a sandbox solution?
The reason is quite simple – your code in a sandbox solution actually executes in a console application – the SPUCWorkerProcess.exe. It is a console application has created an HttpContext and a Page instance, in which your web part class is also instantiated on that page. You don’t have some crucial asp.net pieces as the HostingEnvironment and the VirtualPathProvider – without these two the LoadControl method simply won’t work. And it is not that you don’t have access to the file system, even if you had, the LoadControl method still wouldn’t work because there wouldn’t be a VirtualPathProvider to provide the file to the asp.net compiler. The bad news is that the same holds for the TemplateControl.ParseControl method too.

Microsoft create template supports Visual Web Parts in the sandbox from Visual Studio 2010 you can use when download Visual Studio 2010 Sharepoint Power Tools



No comments: