How to change teamsite text layout programmatically? - sharepoint

I have a code that creates a teamsite. After that I add some web parts to wiki web part zone(rich content area). In SharePoint 2010 user can change a text layout of the rich content in page edit mode.
Is there any way to programmatically change the text layout of the rich text area? I would want to set "two columns with header"-layout after site creation has completed.
My site is created like this.
site = elevatedSite.SelfServiceCreateSite(params.....);
rootWeb = site.RootWeb;
rootWeb.ApplyWebTemplate("STS#0");
SPListItem currentItem = rootWeb.Item;
var xhtml = currentItem[SPBuiltInFieldId.WikiField] as string;
Now I can modify the xhtml string and save it back to the page. I have tried to change it so that it contains exatly the same html structure which have created by sharepoint itself, when changing the text layout. After that change, actually it is not recognized as "two columns with header"-layout in sharepoint. It is still default one-column layout. Is there anybody who knows is it possible to change the text layout of the rich text area programmatically?

I found answer from here http://donalconlon.wordpress.com/2010/05/04/sp2010-creating-a-wiki-page-using-the-om/. SharePoint stores the information about used layout to the hidden span-element in wiki page.
For example, this presents two column layout without the header or footer.
<span id="layoutsData" style="display: none">false,false,2</span>
first false = no header
second false = no footer
2 = two columns

I have been looking for some information on doing the same thing. I found this blog post that checks out the page, edits the content then publish and approves it.
SharePoint 2010 change page content data through Object Model / API – Console Application

If you need to modify pure HTML content, its better to use cutom IHttpHandler (wrapped in dll) and connect it to SharePoint via web.config. Is is also allowing to modify dynamic content like AJAX responses.

Related

Editing Sharepoint Online HTML content using Client Object Model

We have a sharepoint online site with a good amount of pages that have href links to a shared in-house network server. Example: file://servername/sharedFolder This way when the user clicks the href - it directs them to the location in the file explorer if using IE or Edge.
Due to server maintenance - we needed to rename the server. So now "servername" is "servername1". This messes up all the links on the sharepoint site.
I need to iterate over all the pages on the sharepoint site, and fix the hrefs.
I apologize im very new to sharepoint so maybe im missing something very simple.
What i have right now is the following:
using (ClientContext ClientWebContext = new ClientContext("site"))
{
ClientWebContext.Credentials = new SharePointOnlineCredentials("username", ss);
Web web = ClientWebContext.Web;
Microsoft.SharePoint.Client.File file = ClientWebContext.Web.GetFileByServerRelativeUrl("page");
ClientWebContext.Load(web, w => w.Title, w => w.Description, w=> w.Lists);
ClientWebContext.Load(file, f => f.Length, f=> f.ServerRelativeUrl, f=> f.Name, f=>f.);
ClientResult<System.IO.Stream> str = file.OpenBinaryStream();
ClientWebContext.ExecuteQuery();
FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ClientWebContext, file.ServerRelativeUrl);using (FileStream filestream = new FileStream("C:" + "\\" + file.Name, FileMode.Create))
{
fileInfo.Stream.CopyTo(filestream);
}
}
The idea was to download the page - parse the html and update the hrefs, then write the page back out to the sharepoint server. But when i view the file that has been downloaded it doesnt contain any of the html that is actually on the page.
If i go to a page, select "edit", then select "Edit Source" I can view and edit all the html in raw format.
I guess the question is - how do i get this html and how do i pro grammatically update it.
EDIT:
A typical sharepoint page contains a table, cells & text inside of those cells. The text then contains links to the server I was talking about above. The sharepoint site is essentially being used as a wiki for new employees and a resource for existing employees to find information quickly. It doesnt contain many complex web parts and embedded code, mainly just a table, cells and text.
Thanks,
-John
Yeah, I don't think this approach will fly.
Again, different types of SharePoint pages have different web parts. Modern SharePoint site page, Wiki page, web part page. They all can have text web parts and/or page elements that can hold HTML, and in some, the WYSIWYG default presentation can be changed to a HTML editor. Then there are also list web parts, link web parts, and all kinds of stuff that can have an underlying link URL.
But these page elements are SharePoint artifacts. The page elements and their contents are stored in an internal SharePoint database. The page chrome and styling is also stored in different parts of the database. The SharePoint server processes the different parts that make up a page. On the SharePoint server side, these page elements then get translated and rendered into HTML that is served to the end user's browser.
You cannot take this rendered end result and expect to use it to change the underlying source of the HTML.
You need to get to the source. Again, what exactly that source is depends on the type of page used. Just because it is "in SharePoint" doesn't identify the page type.
Sorry, I know this is not what you want to hear, but if you want to manipulate SharePoint content, you need to acquire an understanding of what SharePoint is and what its moving parts are.

change page template based on querystring

I am using one page template which contains master page layout also. Now when i access the page having layout which is displaying in browser. Now i wanted here if i use querystring like below:
http://localhost/Mywebsite/page?AppMode=true
then i wanted here to show only content of the page master layout should not be displayed with page content.
Currently i am using Kentico9.
A page's template is not something you can do with a macro, however you can control a Page Placeholder webpart with a macro/querystring.
So in order to do what you want, this is what you'll need to do.
For the page's actual template, it will pretty much just be a 'blank' page template, with a Page Placeholder webpart in it.
For the page placeholder webpart, set the path to "." (so it shows this page), and the Page Template you can then set with a macro: {% (Convert.ToBool(QueryString.AppMode, false) ? "NotAppModeTemplate" : "AppModeTemplate") %}
Tell me if that does the trick for ya! The only caviote is the only 'control' of the master template used is in the template settings, which can inherit the root or the nearest master template, so if you want one template to use 1 master page, and the other to use a different, you'll have to set the masterpages somewhere in their ancestry and then use the "Inherit from Level 0,1,2..." setting in the Page Template.
Assuming you're doing this using Kentico's ASPX mode of development. Do a simple check for the querystring and set the visibility of the placeholder in code behind. If I were doing this in Portal mode, I'd do that with a macro on a webpart.
I used in master page template conditional layout and that layout i used visible property with macro querystring with my condition except for my content place holder and it is working fine as i wanted.

web part title in xsl

I'm investigating a possible solution where all web parts on my page should be rendered without a chrome, meaning that the default title portion of the web part will be hidden, but the title supplied in the web part properties should be used elsewhere in the web part.
I have found several solutions on how to get the page title but none around how I can crab the web part title and display it using Xsl, would like to return this within the ItemStyle.xsl
I used a method of return the raw xml data for the web part, but by default is the title of the web part not return, and I found no reference other than OuterTemplate.GetTitle() which points to the Title column of a list, to support my solution.
Is this possible?
It is probably not accessible through the xsl itself, as the title of the webpart is not part of the xml data coming through. If you really need it, you could show it on the page and use JQuery/Javascript to scrape it off. Otherwise, I might find a different way to provide the name, maybe with a query parameter.

Where can I find discussion board newform.aspx page to modify?

I have to modify text in discussion board new post page. Now it is showing "Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval."
I have to append some text to this message. I am trying to find discussion board newform.aspx page to modify. Please let me know where can I get that?
Assuming your discussion list is called "Public Discussion" at a site called "http://yoursite"
Connect to the site (http://yoursite) with sharepoint designer
Go to All Files -> Lists -> Public Discussion -> NewForm.aspx
Edit file
Look for <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
Add content as needed
Save file, it will warn you that you are about to save a customised layout.
The message you describe is injected by sharepoint's content approval framework. To custom the messsage, you will most likely need to use javascript to find the message box and change the text.
On my site the html xpath to the node is something like this:
//span[#id='part1']/table/tbody/tr/td[2]
On the file system it will be here:
$sphome / "Name of your discussion board" (this will be a folder) / Forms / newform.aspx
There is a similar question asked here. It describes custom template controls handle the display of this content.
There is also a link here that describes a solution to do this using css. This would allow you to hide the OOB text and then have your own content displayed instead. However, there is some question of it working on broswers other than IE so include this in your testing.

Change Edit Control Block (ECB) Link URL in SharePoint

Is there a way to dynamically change the hyperlink associated with an ECB menu in WSS 3.0? For instance, I have a list with 2 fields. One field is hidden and is a link, the other is the title field which has the ECB menu. The title field currently links to the item's view page - but we want it to link to the link-field's url. Is that possible?
UPDATE - 5/29/09 9AM
I have this so far. See this TechNet post.
<script type="text/javascript">
var url = 'GoTo.aspx?ListTitle='+ctx.ListTitle;
url += '&ListName='+ctx.listName;
url += '&ListTemplate='+ctx.listTemplate;
url += '&listBaseType='+ctx.listBaseType;
url += '&view='+ctx.view;
url += '&';
var a = document.getElementsByTagName('a');
for(i=0;i<=a.length -1;i++)
{
a[i].href=a[i].href.replace('DispForm.aspx?',url);
}
</script>
This gives me a link like so (formatted so it's easier to see):
GoTo.aspx
?ListTitle=MyList
&ListName={082BB11C-1941-4906-AAE9-5F2EBFBF052B}
&ListTemplate=100
&listBaseType=0
&view={9ABE2B07-2B47-4390-9969-258F00E0812C}
&ID=1
My issue now is that the row in the grid gives each item the ID property above but if I change the view or do any filtering you can see that the ID is really just the row number. Can I get the actual item's GUID here?
If I can get the item's ID I can send it with the list ID to an application page that will get the right URL from field in the list and forward the user on to the right site.
I think the easiest solution and one I use regularly to modify default sharepoint functionality without having to install server side code is to inject some javascript onto the page to make the necessary modifications.
The Content Editor webpart is ideal for this if you don't want to edit the page source itself. Together with the IE Developer Toolbar or Firebug to inspect the elements you want to edit you should be able to achieve what you need with just a couple of lines of javascript.
Let me know if you need any further detail on getting this work.
The title/link to edit menu is a computed field - basically a combination of the title and item id. If you look at the definition of the field (off the top of my head I think it's in fields.xml) you should be able to create a modified version in your schema.xml that uses the url field in its RenderPattern.
Following up on Tom's answer, you can use the SharePoint Solution Generator in VseWss 1.3 to generate a Visual Studio solution that can re-create your list. You will faint when you see the huge amount of XML that the views use in the schema.xml file but you will see the render pattern that Tom referred to and you should be able to get a general idea of how to modify it to suit your needs.
Gotta love SharePoint. Where small customizations means "take what I give you or rewrite it from scratch"

Resources