Ejemplo n.º 1
0
        private void AddModulePart()
        {
            String moduleIDString = Request.Params.Get("addmpart");
            Module module         = new Module(int.Parse(moduleIDString));

            //TODO: we could support filtering by module.ViewRoles
            if (module.AvailableForMyPage)
            {
                SiteModuleControl siteModule = Page.LoadControl("~/" + module.ControlSource) as SiteModuleControl;
                if (siteModule != null)
                {
                    siteModule.SiteId = siteSettings.SiteId;
                    siteModule.ID     = "module" + module.ModuleId.ToString();

                    siteModule.ModuleConfiguration = module;
                    siteModule.RenderInWebPartMode = true;

                    WebPart webPart = WebPartManager1.CreateWebPart(siteModule);

                    siteModule.ModuleId = module.ModuleId;
                    Module.UpdateCountOfUseOnMyPage(module.ModuleId, 1);

                    mojoWebPartManager mojoManager = (mojoWebPartManager)this.WebPartManager1;
                    mojoManager.AddWebPart(webPart, this.CenterWebPartZone, 0);
                    mojoManager.SetDirty();
                }
            }
        }
Ejemplo n.º 2
0
        private void AddWebPart()
        {
            String webPartIDString = Request.Params.Get("addpart");

            if (webPartIDString.Length == 36)
            {
                Guid webPartID = new Guid(webPartIDString);

                WebPartContent webPartContent = new WebPartContent(webPartID);
                if ((webPartContent.WebPartId != Guid.Empty) && (webPartContent.AvailableForMyPage))
                {
                    if (HttpContext.Current != null)
                    {
                        String path = HttpContext.Current.Server.MapPath("~/bin")
                                      + Path.DirectorySeparatorChar + webPartContent.AssemblyName + ".dll";
                        Assembly assembly = Assembly.LoadFrom(path);
                        Type     type     = assembly.GetType(webPartContent.ClassName, true, true);
                        WebPart  webPart  = Activator.CreateInstance(type) as WebPart;
                        if (webPart != null)
                        {
                            WebPartContent.UpdateCountOfUseOnMyPage(webPartContent.WebPartId, 1);
                            webPart.ID = Guid.NewGuid().ToString();

                            mojoWebPartManager mojoManager = (mojoWebPartManager)this.WebPartManager1;
                            mojoManager.AddWebPart(webPart, this.CenterWebPartZone, 0);
                            mojoManager.SetDirty();
                        }
                    }
                }
            }
        }