Thursday, February 27, 2014

Sharepoint OOTB pages - content types and fields

Base Page CT - "System Page", ID 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2, columns:
Content Typec042a256-787d-4a6f-8a8a-cf6ab767f12d
Select5f47e085-2150-41dc-b661-442f3027f552
Name8553196d-ec8d-4564-9861-3dbe931050c8
Created8c06beca-0777-48f7-91c7-6da68bc07b69
Titlefa564e0f-0c70-4ab9-b863-0177e6ddd247
Modified28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f
Document Modified By822c78e3-1ea9-4943-b449-57863ad33ca9
Document Created By4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb
Comments9da97a8a-1da5-4a77-98d3-4bc10456e700
Scheduling Start Date51d39414-03dc-4bd0-b777-d3e20cb350f7
Scheduling End Datea990e64f-faa3-49c1-aafa-885fda79de62
Contactaea1a4dd-0f19-417d-8721-95a1d28762ab
Contact E-Mail Addressc79dba91-e60b-400e-973d-c6d06f192720
Contact Name7546ad0d-6c33-4501-b470-fb3003ca14ba
Contact Picturedc47d55f-9bf9-494a-8d5b-e619214dd19a
Page Layout0f800910-b30d-4c8f-b011-8189b2297094
Variation Group ID914fdb80-7d4f-4500-bf4c-ce46ad7484a4
Variation Relationship Link766da693-38e5-4b1b-997f-e830b6dfcc7b
Rollup Image543bc2cf-1f30-488e-8f25-6fe3b689d9ac
Target Audiences61cbb965-1e04-4273-b658-eedaa662f48d
Hide physical URLs from search50631c24-1371-4ecf-a5ae-ed41b03f4499

Page CT, "Page", ID 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39, extra columns:

Browser Titleff92f929-d18b-46d4-9879-521378c689ef
Meta Descriptiond83897e5-2430-4df7-8e5a-9bc06c664992
Meta Keywords45ae2169-585c-440b-aa4c-1d5e981fbbe5
Hide from Internet Search Engines325c00dd-fd91-468b-81cf-5bb9951abba1

Article page CT - "Article Page", ID 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D, extra columns:

Page Image3de94b06-4120-41a5-b907-88773e493458
Page Contentf55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8
Summary Linksb3525efe-59b5-4f0f-b1e4-6e26cb6ef6aa
Bylined3429cc9-adc4-439b-84a8-5679070f84cb
Article Date71316cea-40a0-49f3-8659-f0cefdbdbd4f
Image Caption66f500e9-7955-49ab-abb1-663621727d10
Style Definitionsa932ec3f-94c1-48b1-b6dc-41aaa6eb7e54

PowerShell: get all fields / columns of a content type

this script both prints and write to a file

$site = Get-SPSite http://lamasadmin
$web = $site.RootWeb
$s = ""

foreach ($ctype in $web.ContentTypes)
{
if ($ctype.Id -eq "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2")
{
$ctype.Name + "   " + $ctype.Id
foreach ($field in $ctype.Fields)
{
$field.Title + "   " + $field.Id
$s += '"' + $field.Title + '", ' + $field.Id + [Environment]::NewLine
}
}
}

$s >> "c:\test.csv"

and to write is as html
$s += '<tr><td>' + $field.Title + '</td><td>' + $field.Id + '</td></tr>'

Tuesday, February 25, 2014

Sharepoint Search - Anonymous, Rest API

the wonderful sharepoint search service, how do you enable it in anonymous site?
*i've tested all this in my sharepoint 2013 but as i understand it works the same in 2010.

the 1st point we must understand is that the more we want to enable in an anonymous site the more we need to take down security. so lets start!


initially indexing only the admin site, keeping the anon site without Win Auth will index your most of your published pages, excluding pages you checked the checkbox in their properties names "Dont show is search".


when the search indices an item it also indices it's permissions, therefor anything your anonymous user cant see he wont see as a search result. so the 1st thing he cant see is the admin site (the non-anon), and therefor we need to index the anon site. 


so now i want my list items from my list... how can i get that?


most simple solution is using the rest service (not search rest). that's great as long as you're satisfied with it. but you wont see the items in a regular search page/center nor publishing/other-complex-rich site columns.


and even here you can solve it by asking each single item with like this:
http://server/site/sub/_api/web/lists/getbytitle('list name')/items(item id)/fieldValuesAsHtml
for the usual full formatted or just the text:
http://server/site/sub/_api/web/lists/getbytitle('list name')/items(item id)/fieldValuesAsText

setting anon access to the my admin site partially, choosing list and libraries and setting private permissions to every library wont help here.


still i tried to fight it a little and the 1st thing i tried is to crawl the anon site. now in order for the crawl to be able to run in our anon site he need to log into it, so 1st thing is to allow Windows Authentication, a thing we usually disable in the IIS after setting up the anon permissions. this can be annoying since, at least in my dev machine, the "Search" part of the page, both of a search center, search page, or rest call, all ask for credentials if the Win Auth is enabled, i am still looking about it but currently after a crawl i disable it.
i am still looking either to cut out the auth request or enable crawl without it.
also even there in order to really see the items i needed to deactivate the feature “Limited-access user permission lockdown mode” in Site Collection Feature. 
but then the anon user can get anywhere (and thats bad!) and inside all my libraries so again setting each library in separate and it started to be a mess.

so i went back to full anon, indexing the admin only, having as results pages only.


REST


about the results its the same issue as above.

the rest needs 2 things to work, a special xml you can create with the PS in this blog (at the bottom), he also gives an overview : http://summit7systems.com/enabling-anonymous-sharepoint-2013-rest-search-by-entering-one-url-in-powershell/
note that even after that you need to allow imersonation in the web config : 
<system.web>
    <identity impersonate="true" />
i assume you also need to allow it in the IIS.

also not sure but maybe you need to add a valid xml header to the file <?xml version="1.0" encoding="UTF-8"?>.

now you can make search rest calls, usually with zero results.

i heard something about anonymous libraries but it sounds like the above giving anon permissions so i am not sure about it and still investigating.

btw - my final solution in this case is making a subsite and a page-layout for my items since in my scenario it's helpful.

CONCLUSIONS

IMO the search was mainly designed to non-anon sites, for them there is the standard REST api. after all even standard search like search center or WP cant return list items as results.
therefor if there really is a case where you MUST be using the rest in anon maybe its an architecture mistake? not cause you're mistaken but cause MS never designed it for that.

p.s. remember that after each change you need a full crawl again.