I am trying to find a way to add Page Viewer webpart programatically and display the website in it...., i have a requirement where i will pass the url to display in the page viewer... below is the code... does not work....
ps: i will be have the url from db just for now i just hard-coded to www.cnn.com to for testing purpose...
using (SPSite site = new SPSite("http://servername/sites/test/"))
{
SPWeb web = site.OpenWeb();
SPFile webPartPage = web.GetFile("www.cnn.com"); //NOT SURE ??????
SPLimitedWebPartManager webPartManager = webPartPage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
PageViewerWebPart pvwp = new PageViewerWebPart();
pvwp.Title = "My Page Viewer Web Part";
webPartManager.AddWebPart(pvwp, "TOP", 0);
// not actually needed
//webPartManager.SaveChanges(pvwp);
}
i get this error:
he Web application at http://www.cnn.com could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.