SharePoint 2010
I have an enterprise wiki site, that I exported and imported from one farm to another. However, I exported it form a site collection root site, to a sub site in another site collection. When I browse to any page that was created with the Enterprise wiki template, I get the error:
This page is not using a valid page layout. To correct the problem, edit page settings and select a valid page layout."
The page layout is showing as Basic Page. And works ok for new pages created. How can I fix the page layout, that is in the existing pages?
Any thoughts?
Turns out it's a bug. If you import a publishing site, the pages do not have the correct link to the page layout. No way to fix this through the UI. I had to use PowerShell.
I followed Mahesh's Blog to this MS Support article and used the Manage Content and Structure tool to change the Page Layout. Quite strange (this error seems to be a downstream error from a page that failed to upgrade from SharePoint 2007 and had a XsltListViewWebPart which had an invalid GroupBy setting).
Below is a simpler /similar version of the code in the link copied in case the original goes away (I've added notes about what needs to be changed)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")
$web = Get-SPWeb -Identity "http://web/you/are/modifying"; #Change web that you're modifying on this line
$spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);
$pages = $spPubWeb.PagesList;
foreach($item in $pages.Items)
{
$pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
$url = new-object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
if($url -ne $null)
{
if($url.Url -match 'NameOfPageLayout') #Change Page layout name on this line
{
$newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http://new/rootweb/_catalogs/masterpage/NewPageLayout.aspx, NewPageLayoutName") #Change URL and name on this line
$pubPage.Name
$pubPage.CheckOut()
$pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
$pubPage.ListItem.UpdateOverwriteVersion()
$pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
}
}
}
Related
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.
I wish to remove the PowerApps button from the command bar on e.g. document libraries on a site. But it does not seem to work. N.B. Automate/Flow button are removed / disable as expected.
My initial test was with a PnP template where I set the websettings nodes attr, like this:
<pnp:WebSettings Title="{parameter:SiteTitle}" DisableFlows="true" DisableAppViews="true"
But it did removed the PowerApps button.
Then I tried there PnP PowerShell snippets but without any luck:
$web = get-pnpweb
$web.DisableAppViews = $true
$web.DisableFlows = $true
$web.Update()
Invoke-PnPQuery
$ctx = Get-PnPContext
$ctx.Site.DisableAppViews = $true;
$ctx.Site.DisableFlows = $true;
$ctx.ExecuteQuery();
(Snippet pasted from https://www.cloudappie.nl/disabling-flow-powerapps-buttons/)
I’m petty sure this was working like 2 weeks ago. Any ideas why I can disable PowerApps button.
You could use spfx to upload custom css file to sharepoint online to hide special button.
Example on how to upload css file in spfx:
https://github.com/hugoabernier/react-application-injectcss
similar issue:
https://sharepoint.stackexchange.com/questions/280681/how-to-hide-the-button/280683#280683
I have a custom ASPX page hosted in a SharePoint 2010 document library with one or more web part connections from a custom web part to a SSRS ReportViewWebPart.
The code is automatically generated based on the definition of the page (done through a custom admin interface). It should look like this (and does on most environments):
<WebPartPages:SPProxyWebPartManager runat="server" ID="SPProxyWebPartManager1">
<SPWebPartConnections>
<WebPartPages:SPWebPartConnection
ConsumerID="g_d01bedc6_69b0_4c82_ac64_208be5668ec3"
ID="g_437d9428_bdb2_4d37_927c_6e1a984432f5"
ProviderConnectionPointID="ProviderValue"
ProviderID="g_AE0B5082_A085_4ba8_AD73_A7AC41E71205">
</WebPartPages:SPWebPartConnection>
</SPWebPartConnections>
</WebPartPages:SPProxyWebPartManager>
However, we are seeing a few environments where the connections are missing, like so:
<WebPartPages:SPProxyWebPartManager runat="server" ID="SPProxyWebPartManager1">
<SPWebPartConnections>
</SPWebPartConnections>
</WebPartPages:SPProxyWebPartManager>
Logging reveals that the correct code is being pushed to the document library, so something is stripping out the SPWebPartConnection nodes when the file is added to the document library. Here is the code which adds the file:
byte[ ] byteArray = Encoding.ASCII.GetBytes( page.Definition );
Hashtable properties = new Hashtable( );
properties.Add( "DashboardID", page.ID );
SPFile newFile = folder.Files.Add( String.Format( "{0}/{1}", folder, pageName ), byteArray, properties, true );
I've checked online for examples on adding files to document libraries to make sure I wasn't missing something. AllowUnsafeUpdates is set to true for the SPWeb and it is inside of a using statement, so it should be disposed of correctly.
So far the only commonality between the sites where this is broken is SP1 for SharePoint. I'm also going through and testing each hotfix in a dev environment but I'm having no luck in finding the piece that is causing the connections to be removed.
Any help would be appreciated.
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.
I need to get all dates and people modifications to currenlty displayed page, all changes which have been published and end user can see difference between them.
My page is aspx connected to pageLayout in which is richhtmlfield with article.
How to do that? Is it possible to do that ?
If this is for Contributors while the page is in edit mode, they can select Tools > Version History from the toolbar. Otherwise, you can add a link on the page to Versions that is available to all users:
<a href="/sites/mysite/_layouts/Versions.aspx?list=[GUID]&ID=[ID]&FileName=%2Fsites%2Fmysite%2FPages%2FcurrentPage%2Easpx>Modifications</a>
You will need to fill in the values of the list, ID, FileName parameters manually. To generate the link automatically, I would build a custom page layout that generates the URL in Page_Load as follows:
RevisionHistoryAction versions = new RevisionHistoryAction();
string url = versions.NavigateUrl;
RevisionHistoryAction is in the Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions namespace.