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

Item Updating or Updated Event Occurs twice in Document Library

Item Updating or Item Updated Event in SharePoint 2007 occurs twice, if require checkout option is enabled for document library.

I found the following workaround from Microsoft Support for this issue.

Check the value of vti_sourcecontrolcheckedoutby in BeforeProperties and AfterProperties, if the both values are null then the event […]

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 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”; […]

“The file has been modified by SHAREPOINT\system” Error while Updating InfoPath xml file in SharePoint Library

If you try to update the InfoPath xml file through object model in events/WebParts or through any medium.

While execting the Item.Update() will cause the below error. While updating the InfoPath xml file in ListItem the file and ListItem object getting disconnected.

Item.File.Update() will solve your issue.

StackTrace […]

SharePoint Diagnostics (SPDiag) Tool for SharePoint Products and Technologies

The real power of Office SharePoint Server 2007 and Windows SharePoint Services 3.0 is that they can be endlessly customized to meet a wide variety of business needs. The Protean nature of SharePoint is at once its most powerful feature and its most formidable; the complexity of your SharePoint environment can increase by orders of […]

Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb

I got this below while updating the profile through object model.

Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb

Add web.AllowUnsafeUpdate = true; to solve this issue.

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();