Monday, November 19, 2012

Convert column data type from multiline to single line in SharePoint 2010


If you create a SharePoint list by importing a spreadsheet you will find that in SharePoint 2010 all free text columns are converted to the multiline data type by default.

This is a problem if you want to filter the multiline columns in a list by clicking on the column heading because column filtering will only work if the column is a single line data type.

So to change a multiline data type column to a single line do this:

1.  Browse to the "List Settings" for the list.

2. Click on the multiline column:


3. Change the Rich Text property to Plain text and press OK. Press OK again when warned:

4. Select the same column again as in step 2.

5. You should now see an option to change the data type to Single line of text. Press OK when done and press OK to the warning:



You can also do this in SharePoint 2010 Designer but you must first change the Rich text setting to Plain text and save the changes, then change from multiline to single line, click off the column, OK the warning then save again.

Thursday, November 8, 2012

How to get database records for last 7 days date or last week only


To get the records for the last 7 days, it would be something like:

select RecordDate, Id
from your_table

where RecordDate > DATEADD(day, -7, GETDATE())

To get the records for the last week only (within the last week not last 7 days)


select RecordDate, Id
from your_table

where RecordDate > DATEADD(day, -7, GETDATE())
and DATEPART(week, RecordDate) = DATEPART(week, GETDATE())


This query will return all records having a date later than 7 days before current date/time.

If you don't want the hours to be taken into account, then try something like this (works only on 2008 due to date datatype cast):

select RecordDate, Id
from your_table
where RecordDate > DATEADD(day, -7, cast(GETDATE() as date))
and DATEPART(week, RecordDate) = DATEPART(week, GETDATE())

Here's the version without the hours for 2005:

select RecordDate, Id
    from your_table
    where RecordDate > DATEADD(day, -7, CONVERT(datetime, CONVERT(char(10), GETDATE(), 
101)))
and DATEPART(week, RecordDate) = DATEPART(week, GETDATE())



That's it :)

Sunday, November 4, 2012

Column and View Permissions in SharePoint 2010


Recently I ran into a codeplex webpart that allows you to specificy column and view permissions for SharePoint 2010.

View permissions disable access to some views on a SharePoint Library or list, and the column permissions hide or set columns to ReadOnly for specified groups. Column permissions work on normal list views, where authenticated users will see columns. Column permissions also apply on the three default SharePoint aspx pages:

EditForm.aspx
NewForm.aspx
DisplayForm.aspx

This feature can be downloaded from http://spcolumnpermission.codeplex.com/

Install instructions and a more in depth description is given on the site. Below is a screenshot from list settings page where the view and the column permission for a list/library can be set up/configured



This Solution is only for SharePoint 2010!

Features:
Column Permission

- Hide or Read Only Columns in a List Forms (New/Edit/Display)
- Hide Columns in Views
- Hide Columns in Alert Me Emails
- Specify the permission for Users, SharePoint Groups or Active Directory Groups
View Permission
- Disable Views
- Hide Views in Context Menus
- Automatically Disable Views in Custom WebPart Zones
- Specify the permission for Users, SharePoint Groups or Active Directory Groups

Column Permission:
1. After successful Installation and Activation on Site Collection you will see two new links in your List/Document Library Settings page.