How to place a WebPart in Publishing Page Content

Hi,
when you use a publishing page you are able through the ribbon to add existing webparts into the content of the publishing page.
I would like to add programmatically a webpart into the content of the publishing page. I couldnt find anyting to that question on the web.
Can someone help?
regards
yavuz
Regards
Yavuz
www.ybog.net | Field notes on software development and technology

Try below:
http://sharepoint2010mind.blogspot.in/2012/06/add-webpart-programmatically-publishing.html
http://sharepoint.stackexchange.com/questions/86026/add-programmatically-custom-web-part-to-page-without-web-part-zone
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
string pageName = "NewPage.aspx";
PageLayout[] pageLayouts = pWeb.GetAvailablePageLayouts();
PageLayout newPage = pageLayouts[0]; //Body only type of page layout
PublishingPageCollection pages = pWeb.GetPublishingPages();
PublishingPage nPage = pages.Add(pageName, newPage);
nPage.Update();using (SPSite site = new SPSite("http://win2008/sites/publishing"))
SPWeb web = site.RootWeb;
SPFile page = web.GetFile("Pages/Lipsum.aspx");
page.CheckOut();
using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
Guid storageKey = Guid.NewGuid();
string wpId = String.Format("g_{0}", storageKey.ToString().Replace('-', '_'));
XmlElement p = new XmlDocument().CreateElement("p");
p.InnerText = "Hello World";
ContentEditorWebPart cewp = new ContentEditorWebPart
Content = p,
ID = wpId
wpmgr.AddWebPart(cewp, "wpz", 0);
string marker = String.Format(CultureInfo.InvariantCulture, "<div class=\"ms-rtestate-read ms-rte-wpbox\" contentEditable=\"false\"><div class=\"ms-rtestate-read {0}\" id=\"div_{0}\"></div><div style='display:none' id=\"vid_{0}\"></div></div>", new object[] { storageKey.ToString("D") });
SPListItem item = page.Item;
string content = item["PublishingPageContent"] as string;
item["PublishingPageContent"] = content.Replace("|", marker);
item.Update();
page.CheckIn(String.Empty);
http://sharepoint.stackexchange.com/questions/86026/add-programmatically-custom-web-part-to-page-without-web-part-zone
http://www.zeemanj.net/?p=291

Similar Messages

  • How to programmatically add webpart to publishing page

    How to add visual webpart in publishing page please let me know.
    Thanks in advance

    public void AddTaskListsWebPart()
                SPLimitedWebPartManager manager = null;
                SPFile file = null;
                try
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                        using (SPSite spSite = new SPSite(site id))
                            using (SPWeb spWeb = spSite.OpenWeb())
                                spWeb.AllowUnsafeUpdates = true;
                                file = spWeb.GetFile(pageurl);
                                if (file.CheckOutStatus == SPFile.SPCheckOutStatus.None)
                                    file.CheckOut();
                                    manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
                                    if (manager.WebParts.Count <= 0)
                                        TaskLists objTaskLists = new TaskLists(); //Replace
    TaskLists with your webpart name
                                        manager.AddWebPart(objTaskLists, "zone1",
    0); //replace zoneid and index with yours one.
                                        manager.SaveChanges(objTaskLists);
                                        //pnlTaskLists.Controls.Add(objTaskLists);
                                        file.Update();
                                        file.CheckIn(string.Empty);
                                        file.Publish(string.Empty);
                                        spWeb.Update();
                                spWeb.AllowUnsafeUpdates = false;
                catch (Exception ex)
                    Utility.SPTraceLogError(ex); //Handle your error as per your logic
                finally
                    if (manager != null)
                        manager.Dispose();

  • How to place a image in a page?

    pls anyone guide me? how to place a image in a page?
    thanks,
    screen410099

    Take a look at the code found in this function:
    SDKLayoutHelper::PlaceFileInFrame
    As expected you can find it in the SDKLayoutHelper file usually found in the Common folder of the SDK.  Anyway it has an example of one way of achieving your goal.
    There are other ways as well.  Here is some code from one of my plugins which uses the LoadPlaceGunCmd boss:
              PMRect pRC = itemGeometry -> GetPathBoundingBox(InnerToPasteboardMatrix(pParentTransform));;
              // Create an ImportCmd:
              InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportAndLoadPlaceGunCmdBoss));
              //InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportFileCmdBoss));
              if (importAndLoadPlaceGunCmd == nil)
                  ASSERT_FAIL("importAndLoadPlaceGunCmd invalid");
                  break;
                URI URIPath;
                URIUTILS -> IDFileToURI(path, URIPath);
              // Set the IImportResourceCmdData Interface's data:
              InterfacePtr<IImportResourceCmdData> importFileCmdData(importAndLoadPlaceGunCmd, IID_IIMPORTRESOURCECMDDATA);
              if (importFileCmdData == nil)
                  ASSERT_FAIL("importFileCmdData invalid");
                  break;
              importFileCmdData -> Set(db, URIPath, (K2::UIFlags)0, kTrue, kFalse);
              ErrorCode status = CmdUtils::ProcessCommand(importAndLoadPlaceGunCmd);
              const UIDList* imageList = importAndLoadPlaceGunCmd -> GetItemList();
              if (!imageList || imageList -> Length() == 0)
                  break;
              UIDRef imageFrame = imageList -> GetRef(0);
              InterfacePtr<IHierarchy> imageFrameHierarchy(imageFrame, UseDefaultIID());
              UIDRef newImage(db, imageFrameHierarchy -> GetChildUID(0));
              imageFrameHierarchy -> Remove(imageFrameHierarchy -> GetChildUID(0));
              // Create an placeGraphicCmd:
              InterfacePtr<ICommand> placeGraphicCmd(CmdUtils::CreateCommand(kPlaceItemInGraphicFrameCmdBoss));
              if (placeGraphicCmd == nil)
                  ASSERT_FAIL("placeGraphicCmd invalid");
                  break;
              placeGraphicCmd -> SetItemList(UIDList(newImage));
              // Set the IPlacePIData Interface's data:
              InterfacePtr<IPlacePIData> placePIData(placeGraphicCmd, IID_IPLACEPIDATA);
              if (placePIData == nil)
                  ASSERT_FAIL("placePIData invalid");
                  break;
              placePIData -> Set(pageItemRef, nil, kFalse);
              // Process the ImportAndPlaceCmd:
              status = CmdUtils::ProcessCommand(placeGraphicCmd);
    HTH.
    John

  • How to place download link on jsp page to download files eg. Download PDF

    Hi,
    I have made an appliaction in struts 2 which creates PDF,its working fine now i want to place a link on my jsp page from where i can click and download that PDF file which i have created and store on my local location. Also i want to to know can i place links on my jsp page to download other type of files if i want to give link on my page to download Images or songs how can i do that,
    Help plzzzzzzzzzzzz

    IF You are using jsf then simply <h:outputLink value="file:///D:/Me/Image000.jpg"/>. This generates HTML <a> tag and value attribute replacing with <a> tag's href attribute.If you are using other technologies try to find which tag generates HTML <a> tag.
    I think You also can simply place HTML <a> tag wherever You want

  • How to place SVG image in web page?

    Attempting to use an SVG image for first time, saved out of
    Illustrator CS3. When I try to place it on a web page in
    Dreamweaver CS3, .svg file is greyed out. Dragging it onto page in
    design view just makes a text link to the image, that has to be
    clicked to display the SVG. What I really want to do is use SVG
    file as a background image (800 x 600 px) that scales to fill
    browser window - is that possible?
    System: Mac OS X 10.4.11

    There is no reliable way to size an 800 x 600 background
    image up or down
    according to viewport size. You could center the page. Thus
    your BG image
    would move to center with page color appearing on either side
    on wider
    displays.
    800 x 600 background image is quite large by web standards.
    Most web
    designers prefer to use small images or slices and then tile
    or repeat them
    horizontally and/or vertically.
    Examples here:
    http://alt-web.com/Backgrounds.shtml
    --Nancy O.
    Alt-Web Design & Publishing
    www.alt-web.com
    "driprint" <[email protected]> wrote in
    message
    news:fsk89k$e83$[email protected]..
    > Attempting to use an SVG image for first time, saved out
    of Illustrator
    CS3.
    > When I try to place it on a web page in Dreamweaver CS3,
    .svg file is
    greyed
    > out. Dragging it onto page in design view just makes a
    text link to the
    image,
    > that has to be clicked to display the SVG. What I really
    want to do is use
    SVG
    > file as a background image (800 x 600 px) that scales to
    fill browser
    window -
    > is that possible?
    > System: Mac OS X 10.4.11
    >
    >
    >

  • Site Template and webparts in Publishing Pages

    Hi
    I've created a couple of webparts in SPD and added these to the pages in the Pages Library (Publish). I then export the site as a template (switching publish off first) and create a new sites from the template. Unfortunately the weparts are missing from
    the publish pages but are available in the new site Webparts Gallery. The Site Pages have the Webparts available but the Publishing pages dont. When I exported the SC root web I switched off publishing for the site.
    Why aren’t the weparts appearing on the page created in Pages Library. Ive switched on publishing now in the new site but its made no difference. ?
    I found this blog but it doesnt appear to provide a solution :http://blogs.technet.com/b/stefan_gossner/archive/2007/09/19/save-site-as-template-option-and-the-publishing-feature.aspx
    Thanks

    As I said, templates are not supported when you turn on publishing.  That's why there is no "save site as template" link after you turn on Publishing in a Site Collection.  I assume you are using one of the hacks to navigate directly
    to the page that lets you save the site as a template, since the link isn't there.  That will work for some sites, but clearly won't for yours.  There is no workaround.  Site Templates aren't supported in Publishing environments because they
    aren't reliable.  If you want Page layouts then you need publishing.  If you use publishing then you can't use site templates.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • How to place an image onto each page

    Hi !
    How do I place an image onto each page (like a logo in a sidebar) using Pages 5.5 ?
    Thanks,
    Karsten

    Karsten,
    I am surprised no one has answered you yet - there are so many Pages users here.
    I am not a Pages user but I did find one way here on this thread in an answer from Arno Jannarelly
    insert image to header in Pages, template header
    "If you want any layout item to be repeated to all of the pages of your document, you just have to select the item(s), then go to Arrange/Section Masters/Move Object to Section Master.
    The good thing of this is that you can repeat any item or group of items placed anywhere you want on the page."
    Now when I first tried it I had no luck, until I selected the image and went to Arrange > Section Masters from the main menu, not on the right hand side from the Format/Document area.  
    From there there is an option: Move Object to Section Master.
    You then can format your image with drop shadows, opacity, etc. and it should be there on new pages in Pages. 

  • How to place aggregated fields in the page header or group header

    Hi,
    i have a report where in i have to display a header based on the aggregated value of a field
    currently the field has values like
    row1  blank
    row2  blank
    row3 Cookies
    row4 blank
    I wanted to know how to get the maximum of these rows in the page header i.e. it should come as Cookies for this case.
    Is there any way to get this? it is easy in the footer where i can do a maximum of this field and get the value but not sure how to get this in the group header.How do we group maximum at the page header or group header?
    Require your help on this at the earliest.
    Thanks
    Shilpi

    Hi Shilpi,
    >
    Shilpi Sinha wrote:
    > currently the field has values like
    > row1  blank
    > row2  blank
    > row3 Cookies
    > row4 blank
    >
    Do display these things in a subreport(i mean adda subreport in detail section). And Create a formula in the subreport itself with shared varible for assiging  the maximum value ..
    Then in the main report , create one formula with same shared variable and just display in Header secton..
    Regards,
    Salah.

  • How to place a button in last page....

    Hi,
    I want to place a button in last page, which is used for calling a report. i created a button and place in bottom of the page... and set the property of print object On : last page then i m getting an error message rep -1216.
    Invalid property setting.... pls suggest me what i have to do????
    Thanks In Advance...

    Hi,
    Last page in the sense u have place the button at the bottom of the canvas.
    Can you please double check the Set_item_property Parameters or else please paste the code here and what error message you are getting exactly.
    Regards
    Sri

  • How to programmatically add timeline webpart to publishing page

    Can we add timeline webpart programmatically?
    If yes then please let me know how we can add it?

    Hi Jason,
    Thanks for your reply. It helped me lot but i want to add something to your code.
    1) Added web.AllowUnsafeUpdates to resolve error of disallow to update.
    2) Added TimelineType  and SourceSelection  properties else it shows add setup properties of webpart
    3) manager.WebParts.Count >= 0 Added condition else on every request it adds control.
    Also i want to know few line of code from your answer:
    1) What is the purpose of using storagekey? Why it is needed?
    2) Why you update page items?
    try
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                        using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                            web.AllowUnsafeUpdates = true;
                            SPFile page = web.GetFile("/Pages/Home.aspx");
                            page.CheckOut();
                            using (SPLimitedWebPartManager manager = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
                                if (manager.WebParts.Count <= 0)
                                    SPTimelineWebPart timelineWebPart = new SPTimelineWebPart();
                                    timelineWebPart.TimelineType = SPTimelineWebPart.TimelineTypeTaskList;
    //Task type list
                                    timelineWebPart.SourceSelection = "Tasks"; //list name
                                    manager.AddWebPart(timelineWebPart, "timelineZone", 0);
                            page.CheckIn(string.Empty);
                            page.Publish(string.Empty);
                            web.AllowUnsafeUpdates = false;
                catch (Exception ex)
                    lblError.Visible = true;
                    lblError.Text = ex.Message.ToString();
    Once again thanks for your reply. Please if you can resolve my queries then please reply it.

  • How to place the components dynamically in page facets.

    I have created a page template
    Logo | Header | User Area |
    | | |
    Menu| Content Area 1 | Content Area 2 |
    | | |
    | | |
    | | |
    | | |
    | | |
    | | |
    | Content Area 3 | Content Area 4 |
    | | |
    | | |
    | | |
    Footer
    I am a new bee. i need to create a system that can allow users to configure the componets in the desired place holder place.
    And save their location so that it can load into the same place on login where it was saved earlier.
    Is there any one who can tell me how to do it.
    Tariq mehmood

    Are you talking about end users placing items in specific places or are you talking about developers placing items on your template in specific places?
    For end user runtime customization you might want to look into using MDS.
    See:
    http://download.oracle.com/otn_hosted_doc/jdeveloper/111demos/mds/mds.html
    http://www.oracle.com/technology/products/jdev/11/cuecards111/adf_set_18/ccset18_ALL.html

  • How to place into indesign a specific page of a multipage pdf document through bridge

    Can anyone let me know if this is possible and if so how?
    Many thanks

    Can anyone let me know if this is possible and if so how?
    You can't use Bridge for this directly, you either have to use Acrobat Pro, PS  or other PDF dedicated software to extract the wanted page first and after saving this file you can use Bridge to place it.
    On a Mac you can even use the basic preview application, open the PDF in preview, choose showing thumbnails and just drag and drop the thumb of the wanted page to the folder you are working on in Bridge.

  • SAPSCRIPT how to place item header on next page

    Hi Guys
    The situation iam facing is this
    outside the loop i have printed the item header then iam looping on an internal table which is printing all the items.
    When the o/p is one page this works fine but when the o/p is more than one page the item header on the next page dosent get printed because its outside the loop.
    somewhat like this
    perform print_header.
    loop at itab.
    perform print_item.
    endloop.
    Question is how can i place the item header text element in my sapscript so that it prints automatically before the start of the items on every page?
    Thanks

    Use the following in Text Editor on Script form.
    :/ TOP
    Print the Item header.
    :/ENDTOP.
    Or.
    Use a variable window. To print the header
    So it will come for every new Page.
    Or.
    Define &CURRENT PAGE&
    IF &PAGE& NE &CURRENT PAGE&
    PRINT HEADER
    ENDIF
    &CURRENT PAGE& = &PAGE&
    Hope this resolves your issue.
    Regards,
    Gurpreet

  • I need an idea how to place multiple videos on one page

    Multiple videos on one page in Muse neded for a video portfolio..
    Anyone got a great idea how this can be done please. (or direct me to a tutorial link - doing one is all I can find)
    I am happy with either embedded or Menu linked on objects to videos.
    Youtube is hosting the videos
    I just cant find any way to put hyperlinks or urls in objects and I can not find a way to make small video players in Muse.
    If I scale the container ..things go very weird. eg the video goes tiny and into a corner.
    I feel like I am working with half a tool box!!!
    I cant even find a template where this has been done.
    Any help is appreciated. Thanx.

    That works perfectly thank you.
    Now I am wondering if I can have a single "viewer" that will play any selected video from a button , a menu or other trigger?
    Info for others if required. :  The You tube ID required in the widget setting is not the URL.  Its an alpha/numeric obtained from part of the YT embedding code.
    example - the bold underlined section
    <iframe width="720" height="405" src="//www.youtube.com/embed/w6ZcCOCihuY" frameborder="0" allowfullscreen></iframe>

  • JEditorPnae setCaretPosition ? how to place position on top of page

    Hi,
    i am new to here ,
    sorry if i violate anything.. anything.
    we are making a multimedia cd with swing.
    we show content in a JEditorPane . we paste a html document with paragraphs with known id"s
    15,16,17,18... for example:
    i want to place the caret( or make visible a paragraph)
    Element text=doc.getElement(String.valueOf(paragraphId));
    aJEditorPane.setCaretPosition(text.getStartOffset());
    but this shows the paragraph at the end of visible area. But i want this to be seen at begining of page...
    is it clear or i have talked so much? i do not known. Think u are searchinfg with
    ctrl + F
    when u hit enter resuly seems at bottom.
    ok. thanks for helps..

    You need to scroll the viewport to the top of the scroll pane. You would do something like:
    Rectangle r = textComponent.modelToView( text.getStartOffset() );
    textComponent.scrollRectToVisible( r );

Maybe you are looking for

  • HT201412 IPhone 4S call problem

    On my Iphone 4S when I try to end a call by touching the "end" the screen goes blank before ending.  I hit the home button and the call comes back up still going but then the screen goes blank before I can hit the "end".  Sometimes hitting the "end"

  • Once again - how many times must i repeat this?I need a serial number to activate my Photoshop softw

    I am typing in the information many times! The system is stuypid! I wanty a serial number - all I have is this - https://adobeid-na1.services.adobe.com/renga-idprovider/pages/evp?email=adhatch%40waitrose .com&client_id=support_portal1&locale=en&key=C

  • BT have agreed to refund me for poor email service...

    I've also posted this information as a reply to various other discussions so apologies if you've already read it I have managed to get BT to agree to refund me for poor service since migration to BT mail on 1st October. I recommend others do so too.

  • Info Stored On Pod dissappeared

    I had recently stored a folder of pictures on my ipod when it was connected to the computer to use it as temp external hard drive. i do this often an never have any problems. i went to retrieve the pics and could not find them anywhere. they weren't

  • MSE 3350 and WCS

    Hi All, I have the following getserver info from the MSE 3350, The WCS ver. 7.0.172.0, the initial install documentation shows that the following ports needs to be opened on MSE to have successfull communications between WCS and MSE. Can someone cla