Beispiel #1
0
        public static void AddCustomWebpart(string webPartName, string pageName, string title, SPWeb web, string zoneId, int zoneIndex)
        {
            var webPart = WebPartHelper.GetWebPart(web, webPartName);

            if (string.IsNullOrEmpty(webPart.Title))
            {
                webPart.Title = title;
            }
            WebPartHelper.AddWebPart(web, string.Format("{0}.aspx", pageName), webPart, zoneId, zoneIndex);
        }
Beispiel #2
0
        private static void AddUserControlToPage(SPWeb web, string pageName, string pageTitle, string positionName, int positionNumber, string userControlName)
        {
            var webUrl = web.ServerRelativeUrl;

            if (webUrl.Equals("/"))
            {
                webUrl = "";
            }
            ContainerWebPart containerWebPart = WebPartHelper.GetContainerWebPart(web);

            if (containerWebPart != null)
            {
                containerWebPart.Title = pageTitle;
                //containerWebPart.UserControlPath = "UserControls/" + userControlName + ".ascx";
                containerWebPart.UserControlPath = webUrl + "/" + ListsName.InternalName.ResourcesList + "/" + userControlName + ".ascx";
                WebPartHelper.AddWebPart(web, pageName + ".aspx", containerWebPart, positionName, positionNumber);
            }
        }