Wednesday, February 9, 2011

SharePoint 2010: code for dumping a taxonomy tree

Just customize the data you need from each node type (store, group, set, term).
        private void DumpTaxonomy(string siteUrl)
{
Stack<string> stack = new Stack<string>();
using (SPSite site = new SPSite(siteUrl))
{
TaxonomySession session = new TaxonomySession(site, false);
int nts = 0;
foreach (TermStore ts in session.TermStores)
{
nts++;
int ng = 0;
foreach (Group g in ts.Groups)
{
ng++;
int ns = 0;
foreach (TermSet s in g.TermSets)
{
ns++;
int nt = 0;
foreach (Term t in s.Terms)
{
nt++;
DumpTerm(t, stack, 4);
}
stack.Push(ReportNode(3, nt));
}
stack.Push(ReportNode(2, ns));
}
stack.Push(ReportNode(1, ng));
}
stack.Push(ReportNode(0, nts));
}
while (stack.Count > 0)
{
Console.WriteLine(stack.Pop());
}
}

private void DumpTerm(Term t, Stack<string> stack, int level)
{
int nt = 0;
foreach (Term children in t.Terms)
{
nt++;
DumpTerm(children, stack, level + 1);
}
stack.Push(ReportNode(level, t.Name + " " + nt.ToString()));
}

private string ReportNode(int level, object children)
{
StringBuilder sb = new StringBuilder();
for(int i = 0; i < level; i++)
{
sb.Append("\t");
}
sb.Append(children);
return (sb.ToString());
}

Thursday, February 3, 2011

SharePoint 2010: How to enable developer dashboard

$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$addsetting.Update()

SharePoint 2010: how to get SQL rows for a document in a library

Here's the snippet, just change the doc lib name and doc title.

select * from AllDocs d
join AllLists l
on d.ListId = d.ListId
and upper(l.tp_Title) = 'UPPERCASE DOC LIB NAME'
and upper(d.LeafName) = 'UPPERCASE DOC TITLE'
join AllUserData u
on u.tp_DocId = d.Id

Tuesday, February 1, 2011

SharePoint 2010: "Access denied by Business Data Connectivity" when viewing list that accesses external data

Solution: permissions (either to users if delegation is used, or the app pool account is trusted subsystem is used) need to be assigned through Business Data Connectivity Service in Central Administration site.