Wednesday, February 23, 2011

Points to note while doing Field and List level Validation

Formulas
  1. You can only compare column values to one another in a list level validation.
  2. A validation formula at the column level cannot include any other columns besides itself.  For example, [Column1]>[Column2] is an invalid formula and SharePoint will not allow it to be used at the column level.  In this case, you want to use list-level validation.
  3. There is only one formula available at the list level. 
  4. The formula syntax is similar to that used in Calculated Columns
There are a few dozen functions available - I have not tried every one.  One interesting thing to note is that SharePoint 2010 would not allow me to use the TODAY function, even when validating a Date field.  [DateColumn]>TODAY is not a valid validation formula.

Conflicts
  1. What if you have both column level validation and list level validation?
    1. The column level formulas will be evaluated first, then the list formulas
  1. What if the column and list level validations are in conflict?
    1. Example - at the list level, you require that [Text1] = [Text2], but each column has it's own validation; [Text1]="AAA", and [Text2]="BBB".  In this case, it will be impossible to actually submit a list item.  The column validations are evaluated first, but if the values validate here, they will of course fail the list validation.
  1. What if the list level validation includes columns not included in a particular content type?
    1. If a column used in the list formula isn't available in the current content type, validation will always fail.  This means that if you have multiple content types in your list,  you should not validate at the list level for a column that is not included in all content types on the list.  These columns can only be validated at the column level.

Site Columns
  1. You can set validation on custom columns of the field types listed above
  2. You can override the validation of a site column at the list level

Friday, February 4, 2011

InfoPath forms getting information from Active Directory

I had a request where I had to develop an InfoPath form for a project and user wanted a people picker in that form. In SharePoint lists/libraries we can use a "Person and Group" column which gets info from AD and will display all names but to have the same functionality in InfoPath we have to follow few manual steps BUT the good news is this do not need any programming.

2007 ships with a control called Contact Selector Control that will resolve this issue!

Wednesday, February 2, 2011

Where are all other site templates in SharePoint 2010

I was creating a new publishing site collection SP 2010 and noticed that when I click on "Publishing" tab, there were only two available options:

Custom Site Template with Publishing feature enable in SharePoint 2007

I had a request to create a custom site template for reusability. As we always enable "Publishing Feature" for all team sites, I tried to save an existing site as template. But you know what, site with Publishing feature, does not provide an option to "save site as template".

Then I tried a trick to open save site as template page:

So just to make it clear.  If your subsite is
http://sites/toplevelsite/teamsite/default.aspx
You would go to :
http://sites/toplevelsite/teamsite/default.aspx/_layouts/savetmpl.aspx

Here you should be able to save site as template.BUT the problem was not solved. Doing this, when you try to create a new site from this template, it is not going to work. It will throw an error and your site is not created.

So to explain in one line, you have to save site templates without enabling "Publishing Feature" and then activate it manually after creating a site from this template.

Friday, January 28, 2011

Display list items from one site collection to other site collection

Recently I had a request to display Calendar events from one site collection to other site collection. This way users do not need to readd the same events in both site collections.
I accomplish this I was thinking of web part or a workflow which will solve the process. But there is also another way to share with you.
This can be done by using IFrames, Javascript.Thanks to Christophe I got this code help from
http://blog.pathtosharepoint.com/2009/01/22/a-simple-method-to-display-a-list-in-another-site/

Check this code

Thursday, January 27, 2011

Playing with Notifications in Tasks lists

One of my user had a requirement in one of their sites. The requirement was, they have a Tasks list where tasks are assigned to members of that site.
 
First question was: How can a person get notified when a task is assigned to him/her ?
 
Answer : By default the notification is disabled. To enable it, follow these steps.
Step 1: Open Tasks list in that site.
step 2: Go to Settings (Next to Actions), List Settings.
Step 3: Click on "Advance Settings" link under "General Settings" section.
Step 4: In "E-Mail Notification " section, select "Yes" for "Send e-mail when ownership is assigned?". Leave all other default settings. Click Ok at the bottom of the page.
 
You are done. Whenever a new task is created and assigned to a person, that person will get notified.
 
Second Question: When a assigned person changes Task status from "In Progress" to "Completed", how can my boss gets notified ?
 
Answer:
Step 1: Open Tasks list in that site.
Step 2: Select Actions, Alert me.
Step 3: Type some Title in "Alert Title" section.
Step 4: In "Send Alerts To" section, type your name. To do this, click on small book icon to the right. This will display a dialog box, type your boss name and click OK. Select name and click Add. you will see your name with an underline.
Step 5: Leave default settings in "Change Type" section.
Step 6: In "Send Alerts for These Changes " section select "A task becomes complete".
Step 7: In "When to Send Alerts " section select "Send e-mail immediately" radio button. And Click Ok.
 
That's it. You are done. you will get notified when someone changes task status from "In Progress" to "Completed".
 
You can use the same logic or tweak it a little bit to fit your scenario.
Let me know if you have any questions.

Tuesday, January 18, 2011

Save a custom view and reuse it in another document

Want to reuse existing view from one list/library and copy iy to other list/library.
Follow these steps:
Step 1: Create a new document library called Documents in site 1. Create new view called SourceView with all the columns in it.
Step 2: Create a new document library called Documents in site 2.
Step 3: Open Site 1 in SharePoint designer and navigate to Documents and open Forms folder. Here you will notice SourceView.aspx. Double click and open the page.
Step 4: Open Site 2 in another instance of SharePoint designer and navigate to Documents/Forms folder. Right click and create new aspx page. Name it MyView.aspx.
Step 5: Copy all the content from "SourceView.aspx" opened in step 3 paste it in "MyView.aspx" page.
Step 6: Now replace GUID of source Documents library with destination Documents library GUID.
To get GUID of Site 2 Document library, open Documents library and click Setting, Document library settings.
In the address bar, the URL will have the guid as the last part of the address.
Example:
http://Site2/_layouts/listedit.aspx?List=%7B35A23714%2D25E3%2D42A5%2DB4BA%2D868F31906FA2%7D
Guid would be the last part of the URL:
%7B35A23714%2D25E3%2D42A5%2DB4BA%2D868F31906FA2%7D
Modify the guid to be in the following format:
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
You are alomost done.

You’ll see a popup informing you that “The URL `Documents/Forms/MyView.aspx’ is invalid.
A workaround for this error is to Save MyView.aspx again with different name in same Forms folder. Say we call it "NewView.aspx".

Step 7: Now open Site2 and navigate to Docuements library and click on views drop down and change the view to "NewView" Now you will see all the columns are automatically created.

I know this is a time consuming but this is one way to do it.

SharePoint LINQ Support

With SharePoint 2007, we had to use CAML queries to write queries against the server, using the SPQuery or SPSiteDataQuery objects. You would write your CAML as a string and pass it to those objects, so there were no strongly typed objects or syntax checking as part of the API.  Instead, you would either have to cross your fingers that you got the query right or use a third-party tool to try to generate your CAML queries.  To make this easier, SharePoint 2010 introduces SharePoint LINQ (SPLINQ).  By having a LINQ Provider, 2010 allows you to use LINQ to write your queries against SharePoint in a  strongly typed way with Intellisense and compile-time checking.   Under the covers, the SharePoint LINQ provider translates your LINQ query into a CAML query and executes it against the server.  As you will, you can retrieve the CAML query that the LINQ provider generated to understand what is being passed back to the server.

Sample code in old  days:

SpSite site = new SpSite(http://samlehome.com/);
SpWeb web = site.openweb();
List<SPList> hiddenLists = new List<SPlist>(); // Do not use an SPListCollection here
foreach (SPList list in web.Lists){
if (list.Hidden)
hiddenLists.Add(list);

}
Notice number of lines of code with LINQ:
SPSite site = new SPSite("http://samlehome.com");SPWeb web = site.AllWebs[0];var hiddenLists = from list in web.Lists where list.Hidden select list;