private static string CreateGridView(SPWeb web, string listName, string viewName, string fields)
{
SPList list = web.Lists.TryGetList(listName);
if (null == list)
{
// LogError
return string.Empty;
}
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
string[] names = fields.Split(';');
foreach (string name in names)
{
viewFields.Add(name);
}
SPView view = list.Views.Add(viewName, viewFields, "", 100, false, false, SPViewCollection.SPViewType.Grid, false);
return view.Url;
}
Friday, February 24, 2012
Add to Quick Launch
private static void AddToQuickLaunch(SPWeb web, string viewUrl, string viewTitle)
{
if ((string.IsNullOrEmpty(viewTitle))
(string.IsNullOrEmpty(viewUrl)))
{
return;
}
SPNavigationNodeCollection nodes;
SPNavigationNode node;
nodes = web.Navigation.QuickLaunch;
node = new SPNavigationNode(viewTitle, viewUrl);
nodes.AddAsFirst(node);
}
{
if ((string.IsNullOrEmpty(viewTitle))
(string.IsNullOrEmpty(viewUrl)))
{
return;
}
SPNavigationNodeCollection nodes;
SPNavigationNode node;
nodes = web.Navigation.QuickLaunch;
node = new SPNavigationNode(viewTitle, viewUrl);
nodes.AddAsFirst(node);
}
Monday, November 7, 2011
Create MySite On Server
bool CreateMySiteOnServer(string serverUrl)
{
bool returnValue = false;
Logger.LogVerbose("CreateMySiteOnServer for URL:" + serverUrl);
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite lowPrivilegeSite = new SPSite(serverUrl);
SPSite site = new SPSite(serverUrl, lowPrivilegeSite.UserToken);
lowPrivilegeSite.Dispose();
using (site)
{
Logger.LogVerbose("Using Site:" + site.Url);
bool allowUnsafeUpdates = site.AllowUnsafeUpdates;
bool contextAllowUnsafeUpdates = SPContext.Current.Web.AllowUnsafeUpdates;
UserProfile profile;
try
{
site.AllowUnsafeUpdates = true;
SPContext.Current.Web.AllowUnsafeUpdates = true;
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(serviceContext);
if (false == profileManager.UserExists(GetCurrentUser()))
{
Logger.LogVerbose("Creating User Profile.");
profile = profileManager.CreateUserProfile(GetCurrentUser());
}
else
{
Logger.LogVerbose("Getting User Profile.");
profile = profileManager.GetUserProfile(GetCurrentUser());
}
// Create Personal Site
Logger.LogVerbose("Creating Personal Site.");
profile.CreatePersonalSite();
// If success, we set return value - failure to CreatePersonalSite will throw an exception
returnValue = true;
}
catch (Exception ex)
{
Logger.LogException("CreateMySite.CreatePersonalSite (inner try)", ex);
}
site.AllowUnsafeUpdates = allowUnsafeUpdates;
SPContext.Current.Web.AllowUnsafeUpdates = contextAllowUnsafeUpdates;
}
}
);
}
catch (Exception ex)
{
Logger.LogException("CreateMySite.CreatePersonalSite (outer try) ", ex);
}
return returnValue;
}
Thursday, November 3, 2011
Get Taxonomy Term by ID
static bool GetTermById(Guid idToMatch, TaxonomySession spTaxonomySession, ref Term result)
{
foreach (TermStore ts in spTaxonomySession.TermStores)
{
if (0 == ts.Id.CompareTo(idToMatch))
{
Console.WriteLine(" - matched TermStore: '" + ts.Name + "'");
return false;
}
foreach (Group group in ts.Groups)
{
if (0 == group.Id.CompareTo(idToMatch))
{
Console.WriteLine(" - matched Group: '" + group.Name + "'");
return false;
}
foreach (TermSet set in group.TermSets)
{
if (0 == set.Id.CompareTo(idToMatch))
{
Console.WriteLine(" - matched TermSet: '" + set.Name + "'");
return false;
}
foreach (Term term in set.Terms)
{
if (0 == idToMatch.CompareTo(term.Id))
{
result = term;
return true;
}
}
}
}
}
Console.WriteLine("FAILED - NOT FOUND");
return false;
}
Thursday, July 21, 2011
Creating aspx page in Site Pages
Thursday, May 26, 2011
Enumerate Features ...
Deploying from one box to another, I get the "Feature {guid} not enabled" - now to figure out what that feature is ...
Get-SPFeature is the Powershell command.
http://www.glynblogs.com/2010/08/powershell-commands-to-list-sharepoint-features.html
Get-SPFeature is the Powershell command.
http://www.glynblogs.com/2010/08/powershell-commands-to-list-sharepoint-features.html
Has the details.
Subscribe to:
Posts (Atom)