Tuesday, December 20, 2011

SharePoint Read Resource File Programatically

SharePoint custom solution development might requires some dynamic or configuration values. Generally the high level configurations can be stored in web.config(Ex: external connection string). But if there are more number of configurations required (Es: List columns, Content type names etc.,) we cannot store them in .config file as it is not safe.

So here the resource file comes into picture. Resource file is XML-Based file which holds the data in key-value pair. Resource file is generally used to store huge configurations for re-usability & consistency and Localization.

Resource file (.resx) should be added to 12\Resources directory in the solution as a new item.
The name format is SampleResourceFile.en-US.resx

Usage:
If the solution provides provisioning of lists or libraries with multiple columns programatically using either code or xml, All the column names can be stored in Resource file as a Key-Value pair.

Read Resource File: XML
The resource value for a key can be read in XML as below.
Read Resource File: C# Code
The resource value for a key can be read in c# as below.
string customColumnNameKey = SPUtility.GetLocalizedString("$Resources:CustomColumnNameKey", SampleResourceFile, (uint)CultureInfo.CurrentCulture.LCID); //LCIT is current local languare
To read the resource file programatically, a common wrapper class can be created to read the resource file throughout the solution by passing the key.
public class Resources
{
    /// Resource File Name.
    /// Filename can be configured in web.configured or can be used as constant.
    private const string RESOURCE_FILE_NAME = "SampleResourceFile";

    /// Method to get the singleton instance.
    public static string GetValue(string key)
    {
        return SPUtility.GetLocalizedString("$Resources:" + key, RESOURCE_FILE_NAME, (uint)CultureInfo.CurrentCulture.LCID);
    }
}

string customColumnName = Resources.GetValue("CustomColumnNameKey");

Friday, August 26, 2011

How To Download Folder from SharePoint Document Library or List

Scenario: SharePoint document library download folder

Generally SharePoint is used for Content & Document Management System. If it is more of Document Management System, users will upload and download files and documents quite often to/from document library or list.

Downloading a single document or file is straight forward, by clicking on the file. But there is no straight way to download folder from SharePoint document library. And downloading one by one file from a library is hectic if it has has more number of files (say 100s).

However a folder with all the files can be downloaded easily by following the below steps:
1. Go to the document library or list.
2. Open Explorer View of the respective document library.
3. Drag & Drop the folder from library to local drive.
                               OR
    Select the folder -> right click -> copy, then paste it on the local drive.

Tuesday, August 23, 2011

How To Install IIS7 on Windows7 and Windows Vista

I have faced issues in configuring/installing II7 on my machine (which has windows 7 installed) from Control Panel -> Program Files -> Turn Windows features on or off. It is always throwing an error message "one or more components are not installed".

To address this i found a nice(microsoft) tool Microsoft Web Platform Installer, which installs II7 in a single click.
And also it provides many other microsoft related features installation/configuration.


How To Repair SUSPECT Database

Sometimes we see a SharePoint error "Cannot connect to the configuration database". One of the reasons for this could be the Respective DataBase is set to SUSPECT mode.

Reasons for database SUSPECT state:
1. Database corruption.
2. Not enough space for the SQL Server to recover the database during startup.
3. Insufficient memory or disk space.
4. Unexpected SQL Server Shutdown, Power failure or a Hardware failure.

Follow the below steps to repair the SUSPECT database:
1. Identify all the databases which are in SUSPECT mode
USE master
GO
SELECT NAME,STATE_DESC FROM SYS.DATABASES 
WHERE STATE_DESC='SUSPECT'
GO
Note:Check the latest log for the database which is marked as suspect.
SQL Server -> Management -> SQL Server Logs

2. Get the database first into EMERGENCY mode to repair it
USE master
GO 
ALTER DATABASE "databasename" SET EMERGENCY
GO
Note: The EMERGENCY database is one way which means read-only.

3. Repair the Database in emergency mode
DBCC checkdb('databasename')
ALTER DATABASE "databasename" SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('databasename', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE "databasename" SET MULTI_USER

Thursday, August 11, 2011

SharePoint Feature Activation Dependency

Scinario:
While provisiong two dependent(one on the other) content/solutions through different features, it is that one of the features might need the resources of other while gettting activated. In this scinario the first feature should be activated before the second, to avoid the dependency issues.

Example:
Feature 1. Custom Content Type
Feature 2. Page with Custom Content Type (dependent on custom content type)

To make sure the same through feature provisioning instead manually, we have feature activation dependency attribute which can be specified in feature.xml file. Which doesn't allow to get activated unless until the dependency feature(s) is activated.




Note: Multiple dependencies can be specified for one feature.