Changing the SPWorkflowAssociation.AutoCleanupDays property

By default the SPWorkflowAssociation.AutoCleanupDays property value is set to ‘60’ days, to set this property we need to call the SPList.UpdateWorkflowAssociation(SPWorkflowAssociation) function, SPWeb.Update() won’t work here.   1: SPSite site = new SPSite(“<http://nishandv3:100/sites/DevSite/>”); 2: SPWeb web = site.OpenWeb(); 3: SPWorkflowTemplateCollection collection = web.WorkflowTemplates; 4: SPList list = web.Lists[“Shared Documents”]; 5: SPWorkflowAssociation _asso = null; 6:…


How to hide subsite’s GlobalNavigation nodes/tabs through SharePoint API?

  When we create a site either through UI or OM, it will not come as a tab unless you check the option ‘Site Actions–>Site Setting–>Navigation–>Show subsites to true’. On checking the option results in displaying all the subsites as ‘Tabs’. If you want to hide some of them programmatically, you need to change the…


How to create SearchAlert Programmatically?

Note: Make sure that you have enabled search based alerts SSP-> Search Settings -> Search Based Alerts 1: SPSite spSite = new SPSite(“http://nishand:300/sites/PubSite/Search/”); 2: SPWeb web = spSite.OpenWeb(); 3: Query alertQuery = new KeywordQuery(spSite); 4: alertQuery.QueryText = “Hello” // Keyword 5: SearchAlert searchAlert = new SearchAlert(spSite, alertQuery); 6: searchAlert.InnerAlert.AlertFrequency = SPAlertFrequency.Daily; 7: searchAlert.InnerAlert.Title = “Alert#2″…


How to set user permissions programmatically?

1: SPSite site = null; 2: SPWeb web = null; 3: site = new SPSite(“http://server:100/sites/DevSite/”); 4: web = site.OpenWeb(); 5: SPRoleAssignment roleAssignment = new SPRoleAssignment(“domain\\user”,””,”Nishand”,”Simple Test For You!”); 6: SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor); 7: roleAssignment.RoleDefinitionBindings.Add(roleDefinition); 8: web.RoleAssignments.Add(roleAssignment);   Enjoy!!!


The InfoPath form’s ‘Attachment control doesn’t work with SharePoint Workflow forms.

When we use InfoPath form as a workflow form with an attachment control, on selecting a file says that “The selected files was not found”.This seems to be a small bug:) in the product. Note: It’s not advisable or supportable to customize out of box files (comes with the SharePoint installation). There is a possibility…


How to update Content Types through the Object Model?

When we add a field to the site content type SharePoint doesn’t push-down those changes to the document library and the list level. The below code sample is for push-down all the changes to document libarary and the list level.The sample code from WSS 3.0 SDK doesn’t seem to be working 🙂    SPField field =…


How to create an XMLFormView control in custom aspx page within SharePoint?

Adding “XmlFormView” control to a custom aspx page that provisioned within SharePoint throws an exception “Session state cannot be enabled here.” XmlFormView control requires session state to be enabled. To enable the session, open the web application’s web.config file, 1. Under <httpmodules> enable the session module<add name=”Session” type=”System.Web.SessionState.SessionStateModule”/>2. Set the <page> tag attribute enableSessionState=”true”3. Add…


UserProfileManager object creating fails when we try to create an instance from a SharePoint workflow application.

A work-around to this issue is, execute the code under admin privileges(impersonate the user), you can either follow the Win API impersonation or using the SPSecurity.RunWithElevatedPrivilages() method. You would get errors like, ‘Microsoft.SharePoint.SPException’ base {System.ApplicationException}: {“Cannot complete this action.\n\nPlease try again.”} ErrorCode: -2147467259 UserProfileChangeJobSchedule: ‘new UserProfileManager(context,false).UserProfileChangeJobSchedule’ threw an exception of type ‘Microsoft.SharePoint.SPException’ SPSecurity.RunWithElevatedPrivilages(delegate() { ServerContext…


&quot;User cannot be found.&quot; error when creating an FBA site programmatically through Windows application or a console application.

When we create an FBA site through console app or a windows app, we need to have the membership provider and the role provider information within App.Config file. It would be with the same structure as we have in the web.config file of SharePoint WebApplication.   App.Config for your Windows/Console application should be like this….