Programmatically Retrieve List of Document Libraries

The following code snippet is used to retrieve the list of document libraries.

SPWeb _web = SPContext.Current.Web;

SPListCollection ListColl = _web.Lists;

foreach (SPList _lst in ListColl)

{

if (_lst.BaseTemplate == SPListTemplateType.DocumentLibrary)

November 26th, 2009 | Tags: , , | Category: MOSS 2007, SharePoint Object Model | Leave a comment

How to Use Resource File in SharePoint 2007

Create Resource file using Visual Studio IDE

Copy the resource file into 12 hive resource folder

GetLocalized method from SPUtility to read the values from resource file

Syntax:

SPUtility.GetLocalizedString(“$Resources:<<ResourceFileName,ResourceKeyName>>”, “<<ResourceFileName>>”, lang);

Example:

SPUtility.GetLocalizedString(“$Resources:MyResources,FirstName”, “MyResources”, lang);

Sample Source:

November 8th, 2009 | Tags: , , | Category: MOSS 2007, SharePoint Object Model | One comment

Programmatically Read Alerts for Users in Site Collection

SPAlerCollection class can be used to get the Alert Collection for the User.

The below code snippet is used to read all alerts registered for the site collection users.

private static void GetAlerts()

{

SPSite currSite = new SPSite(“http://uday”);

SPWeb currWeb = currSite.OpenWeb();

SPUserCollection […]

How to set the Interval for Alerts in SharePoint 2007

To set the timer job interval for alerts can set by using the setproperty for the property job-immediate-alerts command in stsadm.

Syntax:STSADM -o getproperty -pn job-immediate-alerts –pv <property value> -url <URL of the Site>

Example:STSADM -o getproperty -pn job-immediate-alerts –pv “every 2 minutes” -url http://uday

[…]

How to Edit InfoPath XML File in Forum Library Programmatically in SharePoint 2007

The below lines of code snippet is to update the infopath xml record(file)

SPWeb _web = SPContext.Current.Web; SPList _list = _web.Lists[“SampleFormLib”];

MemoryStream myInStream = new MemoryStream(item.File.OpenBinary()); XmlTextReader reader = new XmlTextReader(myInStream);

XmlDocument doc = new XmlDocument(); doc.Load(reader);

reader.Close(); myInStream.Close();

XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable); nameSpaceManager.AddNamespace(“my”, “http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-11T12:44:57“);

doc.DocumentElement.SelectSingleNode(“my:Status”, nameSpaceManager).InnerText = “Saved”; […]

Get Timer Job Interval for Alerts

To get the timer job interval for alerts can be retrieved by using the getproperty command in stsadm.

Syntax:STSADM -o getproperty -pn job-immediate-alerts -url <URL of the Site>

Example:

STSADM -o getproperty -pn job-immediate-alerts -url http://uday

Set Duration for New Icon Indicator in SharePoint

To Set the Duration for New icon in SharePoint (the indicator which shows next to new items) access the SharePoint WebApplication object and set the value for DaysToShowNewIndicator.

SPWebApplication WebApp = SPWebApplication.Lookup(new Uri(WebAppURL.Text));

WebApp.DaysToShowNewIndicator = 3;

WebApp.Update();

[…]

SPDisposeCheck Released!

SPDisposeCheck v1.3.1 has been released on MSDN Code Gallery, http://code.msdn.microsoft.com/SPDisposeCheck. This tool will help improve the quality of your SharePoint assemblies. It will inspect your SharePoint assemblies and check that you are correctly disposing of certain SharePoint objects (IDisposable objects which includes SPSite and SPWeb). The tool is based upon the guidance published in this […]

Programmatically Update List Content in SharePoint

Hi Devs,

The Below is the Sample Code to update the Sharepoint list content programmatically by using SharePoint Object Model.

SPSite Site = new SPSite(“http://localhost:21000”); SPWeb Web = Site.OpenWeb(); SPList List = Web.Lists[“Address Book”]; SPListItem ListItem = List.GetItemById(0);

string FullName = string.Empty;

FullName = ListItem[“FirstName”].ToString() + ListItem[“LastName”].ToString(); SPListItem[“FullName”] = FullName; ListItem.Update();