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;