Sunday, December 13, 2009

SPWeb.Users and SPWeb.SiteUsers are the same ?

Well no.

Sounds very close, but there is a difference.


SPWeb.Users - Property returns collection of user objects that are explicitly assigned permissions.


SPWeb.SiteUsers - Property returns collection of user objects that belong to site collection.

Thursday, November 12, 2009

CAML Vs Linq ? What's better ?

A few days ago I had a small project over one of my clients, one of the issues I had to deal with was to iterate via his enormous lists sizes, and to change specific MetaData according to other metadata that he already has.

Then I had to choose how I want to work with those lists

Why Linq ?

1. Easy for the .net developer, no new skills required.
2. intellisense. It's a great deal sometimes.
3. Easy to read your code, no loops, no "weird" syntax.
4. Can combine multiple sources ( XML files, SharePoint lists and databases and more ... )

Why NOT Linq ?

1.Performance issues in some cases. All items are being retrieved from the database.
The filtering phase is being done only by iterating via all all items and comparing them to the where clause. So in large collections we have a major performance problem with Linq.

An example, which we will use later again :

 
//checking if the column address is not empty and the column name equals tothe filter.
//and order it by PostedOn

var resourceListItems = fromSPListItemitemin resourceList.Items
whereitem[“Name”] .ToString().ToLower().Contains(_filter)
&& item[“Adress”].ToString().Length> 0
orderbyitem[“PostedOn”] ascending


Why CAMAL ?

1. Only items that match the filter criteria will be retrieved from the database.
2. There are some wizards to make it easier for writing those queries ( such as : LinqToSharepoint, Linq4SP and some more - just google those names ).

Why NOT CAMAL ?

1. Syntax. No intellisense. Not easy to read.
2. Problematic filtering, not as wide as you can get in Linq. If you want to compare two columns it's not feasible ( I might wrong on that ).

Same example as before in CAML :

 
//checking if the column address is not empty and the column name equals tothe filter.
//and order it by PostedOn, and at last calling getting the collection.

SPQueryquery = newSPQuery();
query.Query= String.Format(“

{0}




”, _filter);

SPListItemCollectionlistItemsColl= resourceList.GetItems(query);


And yes, you can use them both combined , for example :

 

SPQuerycamlQuery= newSPQuery();
camlQuery.Query= String.Format(“

{0}


”, _filter);
var resourceItemsCollection=fromSPListItemiteminresourceList.GetItems(camlQuery)
orderbyitem[“PostedOn”] ascending


Bottom line, it depends on what you need to do :

If you work on a very large collection, you better use CAMAL ( also recommended in the MSDN ).

If you work on a small collection , and the cost of iterating all collection is ok for you, Or when you need to make a certain filtering that requires iteration ( such as column comparison ) then choose Linq.

Enjoy.

Wednesday, November 11, 2009

How to change the regional settings of your site collection

Very simple -

Go to : Site Settings => Modify All Site Settings

Click on "Regional Settings" under "Site Administration" column.
Now just change the time zone...

Good Luck.

Saturday, October 31, 2009

Moss on Windows server 2008 R2

In the last few weeks I have started to sense over my clients the desire of upgrading windows servers from 2003 to 2008.

So if you are about to this move for your Moss WFE server, you better check this link -
http://blogs.msdn.com/sharepoint/archive/2009/10/02/install-sharepoint-server-2007-on-windows-server-2008-r2.aspx

Good luck.

Friday, October 9, 2009

How to check if list is a document library ? Let's Linq it !

Sometimes you need to iterate via the Doclibs of a site for a dedicated reason, and there is no need to iterate via the "regular" lists of the site.

Of course it's very easy so you usually just run something like that -

 
SPWeb web = site.Openweb();
SPListCollection listCol = web.lists;
foreach(SPList list in listCol )
{
//Do your thing
}


So in order to be more efficient, run only in doclibs, and not on all lists that you have in your website ( including hidden ones ).

How you do that ? very simple.

 
SPWeb web = site.Openweb();
SPListCollection listCol = web.lists;
foreach(SPList list in listCol )
{
if(list.BaseType == SPBaseType.DocumentLibrary)
{
//Do your thing
}
}


And to make it even nicer, lets just LINQ it -
 
var docLibs = from SPList list in web.Lists where (list.BaseType == SPBaseType.DocumentLibrary) select list;
foreach (SPList doclib in docLibs)
{
//do your thing
}


Hope it helps.

Tuesday, September 8, 2009

few days ago I came across this nice short video.

Im ashamed to say how much time I spent on doing the same via web services...

Actually, Im just being harsh on myself, because this "idea" is a bit more limited, but still very cute.

Display a SharePoint list on Another Site in 3 minutes from Dux Raymond Sy on Vimeo.

Sunday, August 23, 2009

How to edit / update / change "Read Only" list columns

We had to retrieve data from our archive storage, back to the sharepoint sites. The problem was that when we retrieved the data back to the sharepoint doclib\lists we changed the Meta Data of our items ( such as Modified, Modified By ) which most of them appear as "read only" columns.

The solution - We had to interfere in our lists, and touch those "read only" columns \ Fields. Remembering we had to avoid changing those lists\Doclibs columns and keep the "old" metadata ( before the retrieval process ).

Code Snippet for how changing the data in the "read only" column such as "Modified" -

 

SPFieldCollection colFields = list.Fields;
for (int i = 0; i < colFields.Count; i++)
{
SPField field = colFields[i];
try
{

if (list.Fields[i].Title == "Modified")
{
if (field.ReadOnlyField)
{
list.Fields[i].ReadOnlyField = false;
for (int j = 0; j < list.Items.Count; j++)
{
SPListItem oListItem = list.Items[j];
DateTime date = (DateTime)oListItem[list.Fields[i].Title];

// updating the relvant stuff on that item.

oListItem[list.Fields[i].Title] = date;
oListItem.Update();

}
}
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}


You can play with it more, and adjust it. Hope you got the idea.

Good luck.