Wednesday, July 13, 2011

What's new in SP1 for SharePoint 2010

Last month Microsoft released SP1 for SharePoint 2010, with that we got new capabilities to the API and to the platform.

So What's new ?

A lot to do with Recycle Bin stuff. Such as under SPWeb class we have new method called - "Recycle" which sends our web object to the recycle bin...

New classes such as : SPDeletedSite,SPDeletedSiteCollection,SPDeletedSiteQuery and more - so starting now we can work with deleted sites with out restoring them. Those classes represent deleted sites!

Shallow Copy : cutting short - the time it takes to copy blob of data from one content db to another.

StorMan.aspx : I think it was in Moss, not sure why it was taken off, guess due to performance issues. Now it's back, give you a better view stats-wise about your site.

Content DB limitation AKA SuperSize me :) : The most important thing for me. Now you don't have to panic when your content db reach the 200GB, now it's maximized for 1TB.

Good luck to all of us and happy upgrading!

Sunday, April 10, 2011

How to export/import website with .net

There are three options to export/import website in SharePoint. The most common used to be by Stsadm utility tool, now with SharePoint 2010 we have the option of doing it with Powershell. The third option is by c# and the SharePoint object model.

Here is an example for that :

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Deployment;

SPExportSettings exportSettings = new SPExportSettings();
exportSettings.SiteUrl = "http://oldwebsite";

exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.BaseFileName = "exportfile";
exportSettings.FileLocation = "c:\\";

SPExport export = new SPExport(exportSettings);

SPImportSettings importSettings = new SPImportSettings;
importSettings.BaseFileName = "exportfile";
importSettings.FileLocation = "c:\\";
importSettings.SiteUrl = "http://newwebsite";
SPImport import = new SPImport(importSettings);

Thursday, February 17, 2011

ביצועים - זכרת לשחרר זיכרון ?

אני תמיד נוהג לציין בפני תוכניתני שרפוינט חדשים שעליהם לשחרר אוביקטיים מסויימים ב-API,
לאחר שהורגלו ש"אוסף הזבל" יעשה זאת בשבילם.

מה הבעיה בדיוק ?
חלק מהאובייקטים בשרפוינט עובדים על גבי קוד לא מנוהל, קרי יש לשחרר את הזכרון שהתם תפסו בסוף השימוש.
מי הם ?
SPSite, SPWeb , SharePoint WebService objects.
כל פעם שיש לכם שימוש בהם, זה צריך להדליק לכם תזכורת שכנראה תצטרכו לנקות אחריהם...
גם אם הם מגיעים בוארציות שונות( אך לא תמיד ).

מה יקרה אם לא נעשה זאת ?
1. נצרוך יותר זיכרון בשרת , קרי בעיות ביצועים, שגיאות בלתי צפויות.
2. אתחול רכיבי הזכרון של אפליקצית האירוח של השרפוינט, דבר שיוביל לטעינה מחדש של אתרים בצורה איטית ואף אי זמינות של האפליקציה.

אז זה חשוב, איך עושים את זה ?
כלל האוביקטים הללו יורשים מ
אז נוכל לשחרר את הזכרון בעצמנו.

יש לכך שלוש גישות -

1. שחרור זכרון באופן "ידני"
SPSite site = new SPSite("http://mysite");
//do some work

2. שימוש ב try ו catch
SPSite site = new SPSite("http://mysite");
//do some work
return ...
catch (Exception e ){
//handle the exception

3. שימוש ב USING , הכל אוטומטי...
using(SPSite site = new SPSite("http://mysite")
using(SPWeb web = site.OpenWeb())
\\do more stuff

חשוב להכיר מתי צריך לשחרר זיכרון ומתי לא, למשל שמקבלים אוסף של אתרים, האם יש צורך לשחרר גם אותו או לא ? או למשל אתר שורש , כן או לא ?

ממליץ לקרוא את המאמר הבא כדי להבין את הנושא באופן מושלם
לינק למאמר

Performance-Performance-Performance, short review!

Every time I teach the basics of SharePoint to a .net developer, I make sure he is aware for disposing certain objects in the SharePoint API.

It's wrong to think the garbage collector will dispose objects for you. You have to dispose all the objects that are unmanaged code ( SPSite,SPWeb, WebServices objects ).

If I don't do it, what will happen ?

1. More server memory consume - hence lower performance.
2. More application pool recycles (reaching the limit of it earlier).

So it is important, how should I do that ?

You have 3 approaches:
1. Pure manually
SPSite site = new SPSite("http://mysite");
//do some work

2. Try, catch and FINALLY
SPSite site = new SPSite("http://mysite");
//do some work
return ...
catch (Exception e ){
//handle the exception

3. Using - auto dispose, my favorite. The objects will be disposed once you are done using them automatically.
using(SPSite site = new SPSite("http://mysite"))
using(SPWeb web = site.OpenWeb())
//do more stuff

Just before closing the post -
Remember to check if you need to do it yourslef or not (event though it seems u should), for exmple cases like -
SPSite.RootWeb - Used to be needed, not anymore...
SPSite().OpenWeb - No need to call SPWeb.Dispose, being called auto.
and etc...

So be sure you are familiar with this article to get the full understanding of this issue.
Msdn article

Saturday, February 12, 2011

What are the new enhancements in SharePoint Foundation?

Thought about making some order with all the new stuff we have in SharePoint 2010. I will mention in this post my top 10 enhancements:
  • Service application architecture - Now you can share resources across web application and farms. You probably remember the SSP (R.I.P) that couldn't be shared across farms - now you can share those kind of resources among several farms.
  • PowerShell - Goodbye Stsadm, Hello PowerShell. An easier way to write administrative scripts.
  • SandBox solutions - an option to deploy solution in sitecollection scope (and not WebApplication scope). Let alone that you have much more control of the resources this solution will consume.
  • New events for sites,lists and workflows - more new events we can hook up into (list creation - finally)
  • REST-based access to SharePoint list items - no more using the regular web services sharepoint expose for us. Now we can get from wherever we want data from lists using the REST-based webservices.
  • Client side programing - Good stuff comes in threes. Calling SharePoint object remotely via .net, silverlight and javascript.
  • Claim based security - external identity management. Like facaebook which enables you to authenticate to other websites with your facebook credentials, now you can implement the same in SharePoint.
  • BCS/External lists - Connecting legacy systems into SharePoint lists. make it transparent to the user interface.
  • Linq queries - now it's part of SharePoint 2010. Easier than ever.
  • Controlling query execution - prohibiting large,inefficient queries during pick hours or by any other rule you create.

Saturday, January 15, 2011

Cannot convert value of the paramter from System.String to System.DateTime

There is a very annoying bug in Visual Studio 2005 when you work with GridView and ObjectDataSource ( my customer has an old environment - sorry ).

What's the deal ?

When you try to update any data which is visible in the GridView/ObjectDataSource you might get the error in the title.

What's the cause for that ?

By default, the checking of the dates is being done according to the US format ( MM-DD-YY ). Hence, when you after the 12th day of the month and your system work with EU format ( DD-MM-YY ) , you will get the error in the title.

How to work around that ?

You will have to configure in your Aspx page, under the object data source definition the parameters you are using including their type. In that case, it will take on runtime the local date format, and you won't have the problem I mentioned before.

Example :

Hope it helps! It solved my issue.

Wednesday, December 1, 2010

CAML vs Linq : round two

A while ago I wrote a post about CAML And Linq when working on MOSS, that post was giving an example of what and when to use each one of them ( when you work on MOSS).

Since that post, a newer version of SharePoint came out, the 2010.
Which is definitely worth writing another part ( update ) for that post.

Actually, I should start with the end result, now you can use Linq in all cases and you will get same results ( only in SharePoint 2010 ).

Now, there is the - how come ? Answer : SPMetal.

What SPMetal does ? In a nut shell, creates an entity class that provide another layer in which your Linq code can access directly to the database ( content db ).
Which is in other words, give you the same performance you could only achieve with CAML queries.

So, if you work with SharePoint 2010 you can work with Linq always. You got my approval :)