Automatically restart the failed workflow instances

Recently I came across a situation in which customer had email enabled a document library and he had setup a custom workflow to start whenever any new item is added in the library. This setup was working as expected but when end-users send some higher number of emails at the same time (lets say 20-30…

1

Not to allow Contributor users to access webpart menu of the webparts

One of my customers had a requirement in which Contributor users should not be allowed to access webpart menu of the webparts on the home page. Contributor users will get the webpart menu like below for all the webparts which are present on the page. Our requirement is to remove this menu. There is no…

2

Webpart code to dynamically load a page viewer webpart to display a requested page

1: using System; 2: using System.Runtime.InteropServices; 3: using System.Web.UI; 4: using System.Web.UI.WebControls; 5: using System.Web.UI.WebControls.WebParts; 6: using System.Xml.Serialization; 7:   8: using Microsoft.SharePoint; 9: using Microsoft.SharePoint.WebControls; 10: using Microsoft.SharePoint.WebPartPages; 11: using System.Xml; 12: using System.ComponentModel; 13:   14: namespace WebPart1 15: { 16: [Guid("8517b24e-202c-4319-8960-303996a3fdb6")] 17: public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart 18: { 19: public WebPart1()…

2

Code snippet to copy documents from one document library to another

1: using (SPSite site = new SPSite("http://ms10:200/sites/200")) 2: { 3: using (SPWeb web = site.OpenWeb()) 4: { 5: SPList lib1 = (SPDocumentLibrary)web.Lists["Documents"]; 6: SPList lib2 = (SPDocumentLibrary)web.Lists["Site Collection Documents"]; 7: byte[] fileBytes = null; 8: string destUrl = null; 9: SPFile destFile = null; 10: foreach (SPListItem item1 in lib1.Items) 11: { 12: fileBytes =…

1

Code snippet to create a Tasks list and associate it with a Parallel Approval workflow in a Pages library

The requirement to write this code was, After export/import, workflow modification for approvers was failing. Approvers were not able to perform the Approval workflow operations and then we tested that if we create a new Tasks list and modify the existing Approval workflow association then everything starts working so we needed a code which can…

0

Event handler code to add incoming emails with subject “Discussion [ID]” as replies

Here the users will send emails with subject “DiscussionTitle [Discussion ID]” format. If there is a discussion thread present with specified “[Discussion ID]” then it will add the incoming email as a reply in that thread. If ID is not supplied and if there is no discussion thread present with “DiscussionTitle” then it will create…

0

Code Snippet to remove duplicate workflow associations from a content type

1: using (SPSite site = new SPSite("http://ms9:105")) 2: { 3: using (SPWeb web = site.OpenWeb()) 4: { 5: SPList list = web.Lists["Shared Documents"]; 6: 7: foreach(SPContentType con in list.ContentTypes) 8: { 9: if (con.Name == "Document") 10: { 11: SPWorkflowAssociationCollection assocCol = con.WorkflowAssociations; 12: bool App = false; 13: bool Feed = false; 14: bool…

0

Code snippet to add / modify columns in a list

It iterates through a whole site collection and wherever the list with name “test” it finds, It will do the changes. 1: using System; 2: using System.Collections.Generic; 3: using System.Text; 4: using Microsoft.SharePoint; 5:   6: namespace ConsoleApplication1 7: { 8: class Program 9: { 10: static void Main(string[] args) 11: { 12: using (SPSite…

0

Code sample to aggregate the text from "append changes" column to Multiline text field.

This is a code sample to copy all of the text from the “col1” column to “col2” column. To note again, “col1” is an "append changes" column so the previous edits of the comments field are stored in previous versions of the list item. 1: using System; 2: using System.Collections.Generic; 3: using System.Text; 4: using…

0

Ways to pass security credentials to web service call

[1] 1: WS.Credentials = new System.Net.NetworkCredential(userName, password, domain); If you want to pass explicit credentials and filter the record after that.   [2] http://support.microsoft.com/kb/813834 1: myProxy.Credentials = System.Net.CredentialCache.DefaultCredentials It will pick up the current logged in users’ credentials and return the data for him/her.   [3] Using SharePoint object model, setting up our custom web…

0