Posts

Access SharePoint list item attachements through code

The code to access the list item attachements is a really simple code. The attachments of a list item are stored as a collection of files for each list item. This collection can be access through the Attachments property of the SPListItem object. An example code is shown below. //   get a reference to the attachments collection SPAttachmentCollection attachments = listItem.Attachments; // loop through each file in the collection foreach (SPFile in attachments) {     // your logic }

Update web part properties programatically

Image
Earlier in MOSS 2007, we used SPWebPartCollection objects to modify the web part properties through code. But now it is obsolete. Now we have a new class called SPLimitedWebPartManager which we can use to do the same thing. I have created a Visual web part with a button. On click of this button, we will make a page viewer web part show the www.google.com  page. Below shown is the code The code will loop through all the web parts in the page where this web part is added and check for a web part with title Page Viewer. When a match is found, it will update the ContentLink property of it and reload the page for the changes to be observed. You can use the above code for any web part by casting it to an appropriate type

The local farm is not accessible

Sometimes you might encounter an error as The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered when you try to open Power Shell To resolve it check the following. The SQL Server is up and running The SQL Server is accessible from the machine where you have opened the Power Shell (applicable in a farm environment) The account used to open the Power Shell has db_owner access on the SharePoint_Config database. Logging in as the system account and starting the power shell should resolve the issue if the SQL Server is accessible.

Create web part pages with custom layouts in SharePoint 2010

Image
SharePoint provides web part pages with eight layouts by default. Unfortunately the process of creating web part pages with custom layouts is a little complex. In this post i will show you how you can create web part pages with custom layouts. I have created a component which will deploy an application page which can be used to achieve this. Go to http://archive.msdn.microsoft.com/customspcf  and download the wsp file with the name CustomSPCF.wsp Deploy the solution. This will deploy an application page at /_layouts/customspcf/customspcf.aspx It will add four web part page layouts at 14\Template\1033\Sts\Doctemp\Smartpgs\CustomSPCF\ and four images corresponding to the layout at 14\Template\Images\CustomSPCF\ The below image shows how the application page will look like You can customize the application page and replace the deployed custom layouts or add new layouts. Follow the below steps to replace the exisitng layouts. 1. Go to the applciation page at 14\Templates\L

Information Management Policy settings in SharePoint 2010

Image
Often you will come across situations where you have to do something with your documents after a certain period of time after they have been created/modified. Information Management Policy settings is where you can configure it. Go to you document library or list settings and click on Information Management Policy Settings Select the content type for which you want the settings to be applied. This screen will show you all the content types you have enabled for your list or library. For a document library you will see Document and Folder where as for a list you will see Item and Folder by default.  Click on Document. In the next screen you will see a list of settings that you can configure like enabling Retention, Labels and Barcodes. But we will only concentrate on the Retention part in this post. Select Enable Retention . This will show another link called Add Retention Stage Clicking on Add a Retention Stage will show a pop up. In the pop you can select when the configur

Create Site Collections from Web Template in SharePoint 2010

Image
I happened to work on a project where we had to create site collection based on the web templates. In SharePoint 2010, when you save a site as template, it is saved as a sandbox solution. But as we know, sandbox solutions are site collection scoped. So we will see how we can deploy one of these at the farm level and create site collections using the web template. First we will create a site based on the Team site template, make some changes and save it as template. I have customized the home page a little to make it look different from the default team site template. Now go to Site Settings and click on Save site as template This will save the template to the solution gallery of the site collection Click on the solution gallery link in the success dialog. Use the open with explorer feature and copy the wsp. Open the solution using Visual Studio 2010 now. Create a new SharePoint project of type Import SharePoint Solution and select Deploy as a Farm Solution. Select the

Site Recycle Bin in SharePoint 2010 SP1

Image
SharePoint 2010 SP1 has brought with it an amazing feature using which site collections administrators can restore sites and subsites which were accidentally deleted. Before SP1 we had to go through a painful process of restoring the database from a backup. But the admin can simply go to the second level recycle bin and select the subsite that was deleted and restore it just like any other content inside the recycle bin. In the above picture Sub is the name of the subsite that was deleted. The site collection administrator can see this in the recycle bin. He can select it, click on Restore Selection and the site is back. Very simple process, isn't it ??