Editing Sharepoint Online HTML content using Client Object Model - sharepoint

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.

Related

How to only get the "title" and "main content" of a page using puppeteer?

I'm trying to create a clone of getpocket.com for learning. On that app, every saved link gets converted into a markdown; and it seems like the it's a filtered content with only the page title and body without headers, footers, etc.
I could get the page's title using puppeteer api thru different means:
using page.title()
or get the page's opengraph "og:title"
But how do i get like the summarized version containing only the main content of the page.
Note that i don't know beforehand the "css class" of the main content since i'm planning on just entering a url in a textbox and scrape that site from there.
I have found what i've needed for this scenario.
I used the Readability.js library for making webpages readable by removing some certain html tags. Here's the library.
This library is what mozilla uses behind the scenes when rendering their reader view

How to link to an individual web content item in Liferay?

Let's say that I am using an AUI Carousel to display a news item slideshow.
This is a typical slideshow - a series of images with overlay text and each image/overlay text links to a web content article for the site's news.
It seems that with Liferay 6.2, it's only possible to link to a page containing the article rather than the article itself.
How does one link to an individual article?
The solution here is to use a Display Page; starting with Liferay 6.1, there is the concept of Canonical URLs (see here).
In order to use this, you need two things:
an asset publisher page (in my example here, the page is called News)
when creating the web content item, set the Display Page to the above (News)
Now the content item can be referred to via: http(s)://<site-url>/-/<web-content-item-url-title>
So, if I have a web content item with the name Come Join Us For Lunch, and a site url of http://my-site.com/, the canonical URL for this web content item will be http://my-site.com/-/come-join-us-for-lunch
However, you should always get the actual url-title from
JournalArticle.getUrlTitle()

How to change teamsite text layout programmatically?

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.

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