By: Aaron Steele
Posted:
September 17, 2006 at 11:47 AM
I have a number of queries that I use to manage SharePoint an I wanted to share a few of the more useful ones. On one large portal, there is a proliferation of Sub-Areas which are managed by a number of different users in several different companies. Some of these areas use unique permissions extensively and it has become difficult to keep track of who has what permissions. I use this query to list out the portal structure and show which users and groups have what permissions on the area. This query also makes use of the function I wrote about in a previous article which decodes the portal permissions. DECLARE @SiteRoot VARCHAR(255) DECLARE @AreaNav VARCHAR(4000)
SET @SiteRoot = 'http://localhost/' SET @AreaNav = 'Topics' SELECT @SiteRoot + Webs.FullUrl + '' AS [URL] , @SiteRoot + Webs.FullUrl + '/_layouts/1033/spcatsec.aspx?CatID=' + convert(varchar(255), CatPath.CatID) as [Manage] , case CatDef.InheritSecurity WHEN 1 then 'Inherits' WHEN 0 then 'Unique' END AS [PermSetting] , CatPath.Path AS [AreaNav] , CASE WHEN MemberIsUser=0 and WebGroups.Title IS NULL THEN (SELECT top 1 title FROM webgroups WHERE siteid=Webs.siteid and id=portalperm.UserGroupID) ELSE ISNULL(WebGroups.Title ,UserInfo.tp_Login) END AS [GroupOrUser] , ISNULL(WebGroups.[description],SharePointHelper.dbo.sFn_DecodePermMask(PortalPerm.PortalMask)) AS [Rights] FROM webs LEFT OUTER JOIN CatDef ON replace( CatDef.weburl,'*','') = Webs.fullurl LEFT OUTER JOIN CatPath ON CatDef.catid=CatPath.catid LEFT OUTER JOIN portalperm ON portalperm.permid=CatPath.permid LEFT OUTER JOIN WebGroups ON (portalperm.UserGroupID = WebGroups.[id] and WebGroups.webid=Webs.[id]) LEFT OUTER JOIN userinfo ON (portalperm.UserGroupID= UserInfo.tp_ID) and (UserInfo.tp_SiteID=Webs.siteid) WHERE (CatPath.Path IS NOT NULL) and ( CatPath.Path like '%' + @AreaNav + '%') ORDER BY CatPath.Path, [GroupOrUser], userinfo.tp_login
The abridged output looks similar to this:
| http://localhost/Topics |
Inherits |
:Home:Topics |
Administrator |
Has full control of the Web site. |
| http://localhost/Topics |
Inherits |
:Home:Topics |
Content Manager |
V Ar; V Pg; A Itm; Ed Itm; Del Itm; Mg Per Vws; A/D Per Wb Prts; Up Per Wb Prts; Cncl Chck; A/Mod Pgs; Crt Ar; Mg Ar; Brw Dr; |
| http://localhost/Topics |
Inherits |
:Home:Topics |
Contributor |
Can add content to existing document libraries and lists. |
| http://localhost/Topics |
Inherits |
:Home:Topics |
Member |
V Ar; V Pg; A Itm; A/D Per Wb Prts; Up Per Wb Prts; |
| http://localhost/Topics |
Inherits |
:Home:Topics |
Reader |
Has read-only access to the Web site. |
| http://localhost/Topics |
Inherits |
:Home:Topics |
Web Designer |
Can create lists and document libraries and customize pages in the Web site. |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Administrator |
Has full control of the Web site. |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Content Manager |
V Ar; V Pg; A Itm; Ed Itm; Del Itm; Mg Per Vws; A/D Per Wb Prts; Up Per Wb Prts; Cncl Chck; A/Mod Pgs; Crt Ar; Mg Ar; Brw Dr; |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Contributor |
Can add content to existing document libraries and lists. |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Member |
V Ar; V Pg; A Itm; A/D Per Wb Prts; Up Per Wb Prts; |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
PBCV\john |
V Ar; V Pg; A Itm; Ed Itm; Del Itm; Mg Per Vws; A/D Per Wb Prts; Up Per Wb Prts; Cncl Chck; A/Mod Pgs; Crt Ar; Mg Ar; A Styl; Brw Dr; |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Reader |
Has read-only access to the Web site. |
| http://localhost/Divisions |
Unique |
:Home:Topics:Divisions |
Web Designer |
Can create lists and document libraries and customize pages in the Web site. |
By: Aaron Steele
Posted:
September 16, 2006 at 11:46 AM
There is an undocumented utility in the BINN folder of SQL that will extract binary fields to files (or vice versa). The user has to be a SQL account, not a windows account and has to have read permissions on the table. This can be very useful when you need to extract information from the many binary fields in a SharePoint database. (Note: This utility is only supported in SQL 2000 and not in 2005.)
Here’s the syntax and an example:
TEXTCOPY [/S [sqlserver]] [/U [login]] [/P [password]]
[/D [database]] [/T table] [/C column] [/W"where clause"]
[/F file] [{/I | /O}] [/K chunksize] [/Z] [/?]
| /S sqlserver |
The SQL Server to connect to. If 'sqlserver' is not specified, the local SQL Server is used. |
| /U login |
The login to connect with. If 'login' is not specified, a trusted connection will be used. |
| /P password |
The password for 'login'. If 'password' is not specified, a NULL password will be used. |
| /D database |
The database that contains the table with the text or image data. If 'database' is not specified, the default database of 'login' is used. |
| /T table |
The table that contains the text or image value. |
| /C column |
The text or image column of 'table'. |
| /W "where clause" |
A complete where clause (including the WHERE keyword) that specifies a single row of 'table'. |
| /F file |
The file name. |
| /I |
Copy text or image value into SQL Server from 'file'. |
| /O |
Copy text or image value out of SQL Server into 'file'. |
| /K chunksize |
Size of the data transfer buffer in bytes. Minimum value is 1024 bytes, default value is 4096 bytes. |
| /Z |
Display debug information while running. |
| /? |
Display this usage information and exit. | C:\Program Files\Microsoft SQL Server\MSSQL\Binn>TEXTCOPY /O /D PBCVirtu1_Site /T Docs /C Content /W"where Id = '{0A5498C4-BA8A-4206-8B02-206AAEE9DF8E}'" /F C:\temp\TempFile.doc /S 10.20.1.63 /U temp_recover /P *******
By: Aaron Steele
Posted:
May 1, 2006 at 11:44 AM
A Windows SharePoint Services Site is a set of web sites on a virtual server that have the same owner and share administration settings. Each site collection contains a top-level Web site and can contain one or more subsites. There are several ‘roles’ that have different levels of control over sites at different levels. They are, in ascending level of control, the Site Administrator, the Site Collection Administrator, the Site Collection Owner, and the Server Administrator. This can become confusing especially when trying to determine who has access to the site.
Site Administrators
Have control over a site and its subsites and can:
- delete the site
- add or delete subsites
- change the settings
- view, add, delete, or change all content within the site or subsites
- add and remove users
- send invitations
Site Collection Administrators
Have full administrative rights to all sites and content within a site collection. In addition to having all the rights of the Site Administrator they can:
- add and remove users from the Site Collection Users
- modify User Information throughout the site collection. For instance, can change the e-mail or display name of a user throughout the site collection
Site Collection Owners (and Secondary Owners)
When you create a site collection, Windows SharePoint Services automatically lists you as the site collection owner. You can change the site collection owner via the Manage Site Collection Owners page in Central Administration or by using the site owner operation with Stsadm.exe. Site collection owners and secondary owners are also site collection administrators. In addition to those permissions they also:
- receive e-mail notifications for events, such as the pending automatic deletion of inactive sites
- receive requests for access from users who have been denied access
Server Administrators
By default any user who is a member of the Administrators group on the SharePoint server can manipulate any SharePoint site. This is not always desirable. Assuming you have install the SharePoint Portal Server 2003 Hotfix Package 898547 you can remove the Sever Administrators’ permission by running the following stsadm command:
stsadm -o setproperty -propertyname denymachineadminaccess -propertyvalue 1
References
Windows SharePoint Services Security Model
http://www.microsoft.com/resources/documentation/wss/2/all/adminguide/en-us/stsb03.mspx
Users who are members of the local Administrators group have access to all the content in your Windows SharePoint Services Web sites
http://support.microsoft.com/kb/892295/
Members of a local administrators group can access all portals and pages of a SharePoint Portal Server 2003 site, even if they do not have permissions for the portal areas
http://support.microsoft.com/kb/906171/en-us
By: Aaron Steele
Posted:
April 2, 2006 at 11:44 AM
One of my favorite SQL stored procedures has been hiding in the master database since SQL 7. It's a useful utility for running commands against every database on a given SQL Server named sp_MSForeachDB. It undocumented and may have been created for running updates during SQL upgrades. But we can put it to work for creating reports and other repetitive tasks.
Here's the syntax: EXEC sp_MSforeachdb @command1, @replacechar, @command2, @command3, @precommand, @postcommand
| Parameter |
Desc |
| @command1 |
nvarchar(2000) field specifying the first command to run against each database. May not be blank. |
| @replacechar |
nchar(1) field specifying the character in the command parameters to replace with the database name. Defaults to ? |
| @command2 |
nvarchar(2000) field specifying the 2nd command to run against each database |
| @command3 |
nvarchar(2000) field specifying the 3rd command to run against each database |
| @precommand |
nvarchar(2000) field specifying a command to be run prior any commands against any database |
| @postcommand |
nvarchar(2000) field specifying a command to be run after running all commands |
--Example to print the names of all the databases on the server:
EXEC [sp_MSforeachdb] 'PRINT ''Database: ?''' Results: Database: DKADatabase Database: master Database: model Database: msdb Database: Northwind
--Example to get all the open transactions for every database on the server:
DECLARE @command1 nvarchar(2000) DECLARE @replacechar nchar(1) DECLARE @command2 nvarchar(2000) DECLARE @command3 nvarchar(2000) DECLARE @precommand nvarchar(2000) DECLARE @postcommand nvarchar(2000)
-- Set parameter values SET @replacechar = '?' SET @precommand = 'PRINT ''Server: '' + @@SERVERNAME' SET @command1 = 'USE ? PRINT ''Database: ?''' SET @command2 = 'DBCC OPENTRAN(?) WITH NO_INFOMSGS PRINT'' '' ' SET @command3 = '' SET @postcommand = 'SELECT GETDATE() AS [Completed]' EXEC [sp_MSforeachdb] @command1, @replacechar, @command2, @command3, @precommand, @postcommand
Results: Server: DEV Database: DKADatabase No active open transactions.
Database: master No active open transactions.
Database: model No active open transactions.
Database: msdb No active open transactions.
Database: Northwind No active open transactions.
Completed ------------------------------------------------------ 2006-04-02 17:05:37.527
By: Aaron Steele
Posted:
April 2, 2006 at 11:43 AMGetting the age of a document in days can be a bit of a pain. If you use a calculated column function like = Today - Created the calculation will only be run when the document is added and is not recalculated when the document
library is displayed. To address this we need to add a date calculation in the XSLT data view that will compare the documents Created date against the current time. This can be done using FrontPage.
There are a few things that need to be done before we start editing the view though: First add a new field to the document library. Call it Age or something like that. You can chose any data type but number is right-aligned by default which is what you'll probably want.
Next, create a new view that includes the Age column or add it to an existing view. Be sure your view also includes the data column you want to use as the basis for calculating the age. In this example I'll use the Created column. I'd suggest setting all of your sorting, filtering, and grouping options ahead of time because you won't be able to make the changes using the SharePoint interface later.
Next, enter some dummy data into the Age field; to make editing in FrontPage easier.
Now, open the View in FrontPage and switch to split view. (Be sure to make a back up first, this is easy to mess up.)
- Click on the document list then right-click and select "Convert to XSLT Data View"
- Select one of the values in your custom Age column
- Just above the page in the tag selector you should see <xsl-value-of> highlighted.
- Click on it and select "Edit Tag"
[ImageAttachment]
- You should see something like "<xsl:value-of disable-output-escaping='no' select='format-number(string(@Age), '#,##0.###;-#')'/>"
- Copy this tag and find it in the code editor.
- Comment out the tag and insert the following code below it:
<!-- DATE CALC STARTS HERE --> <!-- Get the current Month and convert to a number--> <xsl:variable name="nowMonth" select="number(substring(ddwrt:ThreadStamp(),5,2))"/> <!-- Get the current Year and convert to a number--> <xsl:variable name="nowYear" select="number(substring(ddwrt:ThreadStamp(),1,4))"/> <!-- Get the current Day and convert to a number--> <xsl:variable name="nowDay" select="number(substring(ddwrt:ThreadStamp(),7,2))"/> <!-- Add the appropriate number of days in the year based on the current selected month example: Jan: add 0 days, Feb: add 31 days from Jan --> <xsl:variable name="nowAddDays"> <xsl:choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:when test="$nowMonth=1"><xsl:value-of select="number(0)"/></xsl:when> <xsl:when test="$nowMonth=2"><xsl:value-of select="number(31)"/></xsl:when> <xsl:when test="$nowMonth=3"><xsl:value-of select="number(59)"/></xsl:when> <xsl:when test="$nowMonth=4"><xsl:value-of select="number(90)"/></xsl:when> <xsl:when test="$nowMonth=5"><xsl:value-of select="number(120)"/></xsl:when> <xsl:when test="$nowMonth=6"><xsl:value-of select="number(151)"/></xsl:when> <xsl:when test="$nowMonth=7"><xsl:value-of select="number(181)"/></xsl:when> <xsl:when test="$nowMonth=8"><xsl:value-of select="number(212)"/></xsl:when> <xsl:when test="$nowMonth=9"><xsl:value-of select="number(243)"/></xsl:when> <xsl:when test="$nowMonth=10"><xsl:value-of select="number(273)"/></xsl:when> <xsl:when test="$nowMonth=11"><xsl:value-of select="number(304)"/></xsl:when> <xsl:when test="$nowMonth=12"><xsl:value-of select="number(334)"/></xsl:when> <xsl:otherwise><xsl:value-of select="number(0)"/></xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Get values for the document created date and convert to numbers--> <xsl:variable name="crYear" select="number(substring(@Created_x0020_Date,1,4))"/> <xsl:variable name="crMonth" select="number(substring(@Created_x0020_Date,6,2))"/> <xsl:variable name="crDay" select="number(substring(@Created_x0020_Date,9,2))"/> <xsl:variable name="crAddDays"> <xsl:choose xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:when test="$crMonth=1"><xsl:value-of select="number(0)"/></xsl:when> <xsl:when test="$crMonth=2"><xsl:value-of select="number(31)"/></xsl:when> <xsl:when test="$crMonth=3"><xsl:value-of select="number(59)"/></xsl:when> <xsl:when test="$crMonth=4"><xsl:value-of select="number(90)"/></xsl:when> <xsl:when test="$crMonth=5"><xsl:value-of select="number(120)"/></xsl:when> <xsl:when test="$crMonth=6"><xsl:value-of select="number(151)"/></xsl:when> <xsl:when test="$crMonth=7"><xsl:value-of select="number(181)"/></xsl:when> <xsl:when test="$crMonth=8"><xsl:value-of select="number(212)"/></xsl:when> <xsl:when test="$crMonth=9"><xsl:value-of select="number(243)"/></xsl:when> <xsl:when test="$crMonth=10"><xsl:value-of select="number(273)"/></xsl:when> <xsl:when test="$crMonth=11"><xsl:value-of select="number(304)"/></xsl:when> <xsl:when test="$crMonth=12"><xsl:value-of select="number(334)"/></xsl:when> <xsl:otherwise><xsl:value-of select="number(0)"/></xsl:otherwise> </xsl:choose></xsl:variable> <!-- subtract the document year from the current year and multiple by 356 days subtract the document month days plus day from the current month days plus day value --> <xsl:value-of disable-output-escaping="no" select="(($nowYear - $crYear) * 365) + ($nowAddDays + $nowDay) - ($crAddDays + $crDay)"/> <!-- DATE CALC ENDS HERE -->
- Save your page.
You may need to replace the @Created_x0020_Date variable with the correct value for your view. It will be slightly different in a List View for instance.
Note: This is a rough calculation only and does not account for leap years or hours and minutes, but those could be added following the same method as above.
Technical Notes: The ThreadStamp() function from the ddwrt namespace function returns the current time (Now) as a string in the format: yyyyMMddHHmmss
|
|
|
|
 |
|
|
|
Managing ConsultantJon Norton is a managing consultant for PointBridge. He has over 15 years of experience in the IT industry primarily in publishing and financial services software development. He is currently focused ... [more]
|
|
|
|
|
|