Useful piece of Powershell to search for a file(s) / item(s) in the site recycle bin and then restore it/them.
Change the regular expression after match to change what files to search for.
1 | $spsite = (Get-SPSite "http://mysite" ) |
Useful piece of Powershell to search for a file(s) / item(s) in the site recycle bin and then restore it/them.
Change the regular expression after match to change what files to search for.
1 | $spsite = (Get-SPSite "http://mysite" ) |
Useful jQuery snippet to add a “View Properties” icon, so the user doesn’t have to use context menu or ribbon (apparently they prefer this)
1 | $(".ms-listviewtable > tbody > tr:first").append("<TH class='ms-vh2 ms-vh2-icon' noWrap>View</TH>"); |
This just adds an extra column to the end with an icon that opens the ‘View Properties’ dialog.
You can either use a Content Editor web part to make it view specific or add it to a global script for all views.
It’s a little hacky, but does the job.
It relies on the title column being available to extract the id of the item.
You may have the need to run some code in a SPServiceContext
of a specific user. e.g. when dealing with user profiles or activities.
This can be achieved by using a combination of the SPUser
, WindowsIdentity
, GenericPrincipal
and the GetContext
method of SPServiceContext
.
From these we can set the HttpContext.Current.User
property to the specified user.
Don’t forget to set the context back after the code has executed!
Below is a helper method that makes this very easy.
I haven’t done any solid testing on performance etc. so the usual caveats apply.
1 |
|
I haven’t seen a massive amount of documentation on MSDN or other posts about this, so I thought I would write a small note.
This details a way of extracting the info you see in the news feed on your ‘My Site’
First of all you need to get the the format used by the ActivityEvent
, this done using ActivityType
and ActivityTemplate
.
1 | ActivityType type = activityMan.ActivityTypes[activity.ActivityEventId]; |
The format variable will now contain something along the lines of “{Pubisher} has posted a note {Link} on {PublishDate}”
Now you could at this point take the corresponding Properties in the ActivityEvent
, but there is a whole load of formatting that needs to be done. The Publisher Tag needs to be turned into a link to the users profile page and display their name, etc, etc.
There is an easier way, you can use the static methods of the ActivityTemplateVariable
.
1 | ActivityTemplateVariable.DateOnlyToString(tag, variable, ContentType.Html, CultureInfo.CurrentCulture); |
The problem here is that you have to pass in an ActivityTemplateVariable
as one of the parameter and there is no obvious way of doing this.
There are no properties or methods in the ActivityEvent
that give you an ActivityTemplateVariable
or is there?
After further investigation of the TemplateVariable
string property, you can see that this actually returns an XML string. This XML string is a de-serialised ActivityTemplateVariable
object.
1 | var variable = (ActivityTemplateVariable)FromXml(item.TemplateVariable, typeof(ActivityTemplateVariable)); |
You can now use this object to pass to the static method of ActivityTemplateVariable
to return the full HTML representation of the tag.
If you then combine that with SimpleTemplateFormat
you can then loop round all the tags and replace them.
1 | var items = SimpleTemplateFormat.SimpleParse(formatToUse); |
If anyone knows a better way then let me know.
1 | string smtp = string.Empty; |
I use a ForEach extension which I’ve included below
1 | public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action) |
More of a reminder to myself.
The internal name for Email
in the hidden User Information list is EMail
and not Email
(Note the capital EM at the beginning EMail).
I came across this when doing a SiteDataQuery
on this list and using Email
rather than EMail
The email was never returned in the DataTable.
For a standard team site (STS#0) the GlobalNodes SPNavigationNodesCollection will contain three SPNavigationNode objects.
Home, Quick Launch and SharePoint Top Navigation Bar, these each have Ids of 1000, 1002 and 1025 respectively.
The problem occurs if you delete Quick Launch or SharePoint Top Navigation nodes. Even if you then add them back in a new ID is generated and SPWeb.Navigation.TopNavigationBar looks for child nodes under a node with an Id of 1002 (This is hard coded).
Through the API this means that SPWeb.Navigation.TopNavigationBar will always be null and through the SharePoint UI an error will be returned to the user (“Value does not exist in that range”).
The only ways I have found to fix this is to delete and re-create the site or (Microsoft please close your ears) get the site id and web id and query the NavNodes table in the content database the site collection sits in and add the following records
SiteId | WebId | Eid | EidParent | NumChildren | RankChild | ElementType | Url | DocId | Name | DateLastModified | NodeMetaInfo | NonNavPage | NavSequence | ChildOfSequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
C803FD13-27FA-475F-909C-2CE5B2048E1B | A31E8093-1505-4E1C-B7CC-04D6B952A33F | 1000 | 0 | 0 | 0 | 0 | NULL | A31414EE-953B-44CC-A37E-4D5D643B002A | Home | 2008-04-04 11:28:21.000 | NULL | False | False | False |
C803FD13-27FA-475F-909C-2CE5B2048E1B | A31E8093-1505-4E1C-B7CC-04D6B952A33F | 1002 | 0 | 0 | 2 | 1 | NULL | NULL | SharePoint Top Navigation | 2008-04-04 11:28:21.000 | NULL | False | True | False |
C803FD13-27FA-475F-909C-2CE5B2048E1B | A31E8093-1505-4E1C-B7CC-04D6B952A33F | 1025 | 0 | 0 | 1 | 1 | NULL | NULL | Quick Launch | 2008-04-04 11:28:21.000 | NULL | True | True | False |
I have been trying to rebuild a development environment recently using DBA created tables.
Every time I ran the PSCONFIG -cmd configdb -create
command it ran and then threw an error.
The error message above was logged.
After looking through the tables, I noticed that some of the tables in both the config db and the config admin db had been created under the user account I had been running the installation under and some had been created under dbo.
There are a couple of SQL scripts in the layouts folder under SQL that are run to create the schemas and here I think is the problem.
Most of the CREATE TABLE
statements using the following syntax CREATE TABLE [dbo].[TableName]
, but there are a few tables in both databases that just use CREATE TABLE TableName
.
The error occurs because further SQL script is then referencing [dbo].[TableName]
, but these tables don’t exist under the dbo user schema, so it errors.
The solution is to change the SQL scripts so all CREATE TABLE
statements have [dbo]. infront of them. Before you run it again you will need to clear out all the objects from both the databases.
We have some rather quirky database rights in our environment, but the install account and the farm service account both had dbcreator and secuirtyadmin rights and were in the db_owner role for each of the databases.
To match the ScopeId in the EventData property of the SPAuditEntry
to a SPListItem
you need to use the hidden column ScopeId and not the Id property of SPListItem
.
Here is what I mean.
The following XML is returned in the EventData
proprty for a SPAuditEventType
of SecRoleBindUpdate
. To match the Scope
returned in the XML to SPSite
, SPWeb
and SPList
object you would use the Id
property of this object, but not for the SPListItem
.
1 | <roleid>1073741826</roleid> |
You need to use the ScopeId
column of the SPListItem
So why can’t I just use the SPAuditQuery.RestrictToListItem
method to return the audit entries for that SPListItem
.
It doesn’t work, that’s why and this has been confirmed by MS Support.
Here is a workaround that will link the ScopeId to the SPListItem that triggered the audit entry
1 | using System; |
We were getting an error on one of our Load balanced web servers.
First of all we got “Attempted to read write to protected memory” error followed by the “The path specified cannot be used at this time” which is then logged every minute in the event viewer on our server.
This then ends up using all the resources on that server, which then makes the server become unavailable. Once the machine becomes unavailable it will move onto the next server and kill that one.
This was reported to Microsoft support and they identified it as a bug that will be fixed in SP1.
In the meantime the following will need to be done to work around this problem.
This is a particularly scary bug to be appearing in a “Production” ready product, especially as it is only happening in the farm environment and can take down you whole farm.
I believe there needs to be more information on the whole way SharePoint propagates between servers in a farm, there seems to be little understanding of it presently.