You are currently browsing the tag archive for the 'Programming' tag.

http://msdn.microsoft.com/en-us/library/cc627284.aspx

 
OverviewIn Microsoft Visual Studio 2008, you can create custom activities that can be consumed in workflows. Creating custom activities lets you encapsulate business logic that applies to different scenarios and that can be used in different workflows. This Microsoft Office Visual How To demonstrates how to create a custom activity to send an e-mail message with an attachment.

Code ItFirst, you must create your custom activity. Then, you can add that to a workflow project and use it to send an e-mail message with an attachment.

Creating a Custom Activity Project

First, create a Visual Studio 2008 Workflow Activity Library project.

To create a Visual Studio 2008 Workflow Activity Library project

  1. Open Visual Studio 2008.
  2. On the File menu, point to New, and then click Project.
  3. Under the Workflow Project Type, select the Workflow Activity Library project template.
  4. In the Name box, type SendMailWithAttachmentActivity, and then click OK.
  5. Rename Activity1 to SendMailWithAttachmentActivity.

Coding Custom Activity

Now that you have a Custom Activity project, you must add code to send an e-mail message with an attachment.

To add code to send an e-mail message with an attachment

  1. The first thing you must do is change your class declaration to inherit directly from Activity instead of SequenceActivity.

    Open your activity in code view, and change SequenceActivity to Activity. Your class definition should look like the following.

    public partial class SendMailWithAttachmentActivity : Activity
    { …

  2. Now you must create some Dependency Properties. Add the following fields inside your class definition.

        public static DependencyProperty ToProperty
          = DependencyProperty.Register(
              "To", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty FromProperty
          = DependencyProperty.Register(
              "From", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty CCProperty
          = DependencyProperty.Register(
              "CC", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty SubjectProperty
          = DependencyProperty.Register(
              "Subject", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty BodyProperty
          = DependencyProperty.Register(
              "Body", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty AttachmentProperty
          = DependencyProperty.Register(
              "Attachment", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty SmtpServerProperty
          = DependencyProperty.Register(
              "SmtpServer", typeof(string), typeof(SendMailWithAttachmentsTest));
    
        public static DependencyProperty InvokeEvent
          = DependencyProperty.Register(
              "Invoke", typeof(EventHandler), typeof(SendMailWithAttachmentsTest));

    Notice that the last field, InvokeEvent, is of type EventHandler. This enables you to add custom code to your activity when it is used in a workflow.

  3. Now, you must add properties for your fields. Add the following code under the fields you just added.

       [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
         [ValidationOption(ValidationOption.Required)]
         [Browsable(true)]
         [Description("Enter any e-mail recipients, separated by semicolons")]
         public string To
         {
            get { return ((string)(base.GetValue(SendMailWithAttachmentsTest.ToProperty))); }
            set { base.SetValue(SendMailWithAttachmentsTest.ToProperty, value); }
         }
    
          [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
         [ValidationOption(ValidationOption.Required)]
         [Browsable(true)]
         [Description("Enter the e-mail sender")]
         public string From
         {
            get { return ((string)(base.GetValue(SendMailWithAttachmentsTest.FromProperty))); }
            set { base.SetValue(SendMailWithAttachmentsTest.FromProperty, value); }
         }
    
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [ValidationOption(ValidationOption.Optional)]
        [Browsable(true)]
        [Description("Enter any carbon copy recipients, separated by semicolons")]
        public string CC
        {
           get { return ((string)(base.GetValue(SendMailWithAttachmentsTest.CCProperty))); }
           set { base.SetValue(SendMailWithAttachmentsTest.CCProperty, value); }
        }
    
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [ValidationOption(ValidationOption.Required)]
        [Browsable(true)]
        [Description("Enter the e-mail subject")]
        public string Subject
        {
           get { return ((string)(base.GetValue(SendMailWithAttachmentsTest.SubjectProperty))); }
           set { base.SetValue(SendMailWithAttachmentsTest.SubjectProperty, value); }
        }
    
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
         [ValidationOption(ValidationOption.Optional)]
         [Browsable(true)]
         [Description("Enter the body text of the e-mail")]
         public string Body
         {
            get { return ((string)(base.GetValue(SendMailWithAttachmentsTest.BodyProperty))); }
            set { base.SetValue(SendMailWithAttachmentsTest.BodyProperty, value); }
         }
    
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
         [ValidationOption(ValidationOption.Optional)]
         [Browsable(true)]
         [Description("Enter an attachment file path")]
         public string Attachment
         {
            get { return ((string)(base.GetValue
              (SendMailWithAttachmentsTest.AttachmentProperty))); }
            set { base.SetValue(SendMailWithAttachmentsTest.AttachmentProperty, value); }
         }
    
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
         [ValidationOption(ValidationOption.Required)]
         [Browsable(true)]
         [Description("Enter the Smtp Server for the email")]
         [DisplayName("Smtp Server")]
         public string SmtpServer
         {
            get { return ((string)(base.GetValue
              (SendMailWithAttachmentsTest.SmtpServerProperty))); }
            set { base.SetValue(SendMailWithAttachmentsTest.SmtpServerProperty, value); }
         }

  4. Now, you must add a property for your InvokeEvent field. This EventHandler property lets you add code in a workflow to interact with this activity programmatically. Add this code under the Properties you just added.

       [DescriptionAttribute("Invoke")]
       [CategoryAttribute("Invoke Category")]
       [BrowsableAttribute(true)]
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
       public event EventHandler Invoke
       {
          add
          {
             base.AddHandler(SendMailWithAttachmentsTest.InvokeEvent, value);
          }
          remove
          {
             base.RemoveHandler(SendMailWithAttachmentsTest.InvokeEvent, value);
          }
       }

  5. Add a using statement at the top of the class. This enables you to access the ASP.NET 2.0 Mail namespace for sending your e-mail message. Add the following code.

    using System.Net.Mail;

  6. The last thing you must do here is override the Execute method. Add the following method inside your class definition.

        Protected override ActivityExecutionStatus
          Execute(ActivityExecutionContext executionContext)
        {
            // Raise Invoke Event to execute custom code in the workflow.
            this.RaiseEvent(SendMailWithAttachmentsTest.InvokeEvent,
              this, EventArgs.Empty);
    
            // Set reference to Smtp Server.
            SmtpClient smtp = new SmtpClient(SmtpServer);
    
            // Create mail message.
            MailMessage msg = new MailMessage();
            msg.To.Add(To);
            msg.From = new MailAddress(From);
            if (!String.IsNullOrEmpty(CC))
            {
                msg.CC.Add(CC);
            }
            if (!String.IsNullOrEmpty(Subject))
            {
                msg.Subject = Subject;
            }
            if (!String.IsNullOrEmpty(Body))
            {
                msg.Body = Body;
            }
            if (!String.IsNullOrEmpty(Attachment))
            {
                msg.Attachments.Add(new Attachment(Attachment));
            }
    
            // Send the e-mail.
            smtp.Send(msg);
    
            // Indicate that the activity has completed.
            return ActivityExecutionStatus.Closed;
    }

Installing a Custom Activity

Before you can use your custom activity, you must install it in the global assembly cache (GAC). For an assembly to be installed in the GAC, you must give it a strong name.

To install the custom activity to the GAC

  1. First, give your assembly a strong name. In Solution Explorer, right-click the project, and then select Properties.
  2. Select the Signing tab.
  3. Select the Sign the assembly check box.
  4. In the Choose a strong name key file list, select New.
  5. In the Key file name text box, type Key.
  6. In this demonstration, we are not concerned with security, so clear the Protect my key file with a password check box. Click OK.

    Now your assembly is strong named, and all you have to do is install it to the global assembly cache.

  7. Save and build the project.
  8. Open a Visual Studio 2008 command prompt.
  9. Navigate to the Activity solution directory, and run the following command:

    gacutil /if SendMailWithAttachmentActivity.dll

Now, that you have successfully installed your activity, you can use it from a workflow project.

Creating a Workflow Project

Next, you create a Sequential Workflow project to use your custom activity.

To create a Visual Studio 2008 Sequential Workflow project

  1. Start Visual Studio 2008.
  2. On the File menu, point to New, and then click Project.
  3. Under the Office Project Type, select the SharePoint 2007 Sequential Workflow project template.
  4. In the Name box, type SendEmailWithAttachmentWF. Click OK.
  5. Type a valid SharePoint Web URL. The example uses http://moss.litware.com. Click Next.
  6. Select a library or list to associate with your workflow, and click Next.
  7. Leave the default options for how a workflow can be started, Manually by users and When an Item is created. Click Finish.

Adding a Custom Activity to the Toolbox

Now that you have created your Sequential Workflow project, you must add your custom activity to your Toolbox before you can use it.

To add the custom activity to the Visual Studio 2008 Toolbox

  1. On the Tools menu, select Toolbox items.
  2. Select the Activities tab.
  3. Click Browse, and browse to the SendMailWithAttachmentActivity.dll in your Activity solution directory. Click Open.
  4. Click OK.
  5. Your activity is now available in the Toolbox.

    Figure 1. Toolbox with new activity available

    Toolbox with activity available

    Note Note:

    If you have a toolbox category selected, the activity is added to that category by default. You can drag the activity to another category if you want.

Adding a Custom Activity to the Workflow

Now, you must add your custom activity to your simple workflow.

To add the custom activity to the workflow

  1. From the Toolbox, drag the SendMailWithAttachmentActivity to be under the onWorkflowActivated1 activity.
  2. Open the Properties window, and rename it to sendMailWithAttachmentActivity.
  3. You can set the activity properties from within the Properties window. Instead, you will do that in code. Select the Event view in the Properties window.
  4. You should see a single event, Invoke. Double-click this property.

    Figure 2. Properties window

    Properties window 

    This takes you to the code-behind class, and you will see that a method stub has been auto-generated for you.

  5. Add the following code inside this method.

        SendMailWithAttachmentActivity.To = "nicolec@litwareinc.com";
        SendMailWithAttachmentActivity.From = "willisj@litwareinc.com";
        SendMailWithAttachmentActivity.CC = "willisj@litwareinc.com";
        SendMailWithAttachmentActivity.Subject = "Email with Attachment Testing.";
        SendMailWithAttachmentActivity.Body = "This email should have an attachment.";
        SendMailWithAttachmentActivity.Attachment
          = @"C:\Documents and Settings\Administrator\Desktop\code snippets.txt"; 
    
        SendMailWithAttachmentActivity.SmtpServer =
          workflowProperties.Site.WebApplication.OutboundMailServiceInstance.Server.Address;

  6.  
Note Note:

The purpose of this demonstration is to show you how to create and consume a custom activity. In a real-world scenario, you would never hard-code these values. You would retrieve them programmatically, or possibly through an Initiation form or a Task form.

Running the Workflow Project from Visual Studio 2008

Press F5 to run your workflow. When you activate this workflow on a document in a document library, an e-mail message is generated and sent with the attachment you specified.

Figure 3. E-mail message with attachment

E-mail with attachment

http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5%2D28d9%2D464f%2Db1c9%2D91e07c8f7e47&ID=60

In the new version of the Content By Type webpart, I added the option to rollup items into a calendar. In a later post I will describe how you can do that using the webpart. In this post I will show you how I did it in the code. When you start it all seems very easy, but there were a few things that caused me some headaches. I hope you don’t run into them as well after reading this item.

Step 1 – Setting up the controls

I implemented all the calendar specific code in a special control:

public class SharePointCalendar : Control

In the CreateChildControls of my webpart, I just add this control to the collection:

protected override void CreateChildControls()
{
    base.CreateChildControls();
    SharePointCalendar calendar = new SharePointCalendar();
    Controls.Add(calendar);
}

In the CreateChildControls of my SharePointCalendar class, I setup the SPCalendarView and add it to the controls collection:

private SPCalendarView _view;

/// <summary>
/// Create the SharePoint calendar. Uses the SharePoint SPCalendarView object.
/// </summary>
protected override void CreateChildControls()
{
    base.CreateChildControls();
    _view = new SPCalendarView();
    _view.EnableViewState = true;
    _view.Width = Unit.Percentage(100);
    _view.DataSource = GetCalendarItems();
    DataBind();
    Controls.Add(_view);
}

You can find SPCalendarView in the Microsoft.SharePoint.WebControls namespace.

Step 2 – Adding data and testing

The data that will be displayed in the calendar is loaded in GetCalendarItems. In this case it is dummy data, but you will get the idea:

private SPCalendarItemCollection GetCalendarItems()
{
    // Create a new collection for the calendar items
    // This is an item with a start and end date.
    SPCalendarItemCollection items = new SPCalendarItemCollection();

    // Add the first dummy item
    SPCalendarItem item = new SPCalendarItem();
    item.StartDate = DateTime.Now;
    item.EndDate = DateTime.Now.AddHours(1);
    item.hasEndDate = true;
    item.Title = "First calendar item";
    item.DisplayFormUrl = "/News";
    item.Location = "Utrecht";
    item.Description = "This is the first test item in the calendar rollup";
    item.IsAllDayEvent = false;
    item.IsRecurrence = false;
    item.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);
    items.Add(item);

    // Add the second item. This is an all day event.
    SPCalendarItem item2 = new SPCalendarItem();
    item2.StartDate = DateTime.Now.AddDays(-1);
    item.hasEndDate = true;
    item2.Title = "Second calendar item";
    item2.DisplayFormUrl = "/News";
    item2.Location = "Utrecht";
    item2.Description = "This is the second test item in the calendar rollup";
    item2.IsAllDayEvent = true;
    item2.IsRecurrence = false;
    item2.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);
    items.Add(item2);

    // return the collection
    return items;
}

If you now build your webpart and add it to a page, it should look like this:

calendar01

Step 3 – The ViewType

Looks nice and it indeed it very simple to do. But now you click one of the links “Week” or “Day” to switch to the daily or weekly view. That doesn’t work. The webpart simply does what it does and it shows you the monthly view. If you look at the url however, you will see that the calendar view added a querystring parameter called “CalendarPeriod“.

Add the following snippet to the CreateChildControls of the SharePointCalendar to make it work:

if (Page.Request.QueryString["CalendarPeriod"] != null)
{
    switch (Page.Request.QueryString["CalendarPeriod"].ToString().ToLower())
    {
        case "day":
            _view.ViewType = "day";
            break;
        case "week":
            _view.ViewType = "week";
            break;
        case "timeline":
            _view.ViewType = "timeline";
            break;
        default:
            _view.ViewType = "month";
            break;
    }
}

The documentation for the ViewType property shows you the possible values, but please notice that you need to set them in lower case!. Not sure what the option “timeline” does. It looks like a normal monthly view if you use it.

Step 4 – The DisplayFormUrl problem

The property DisplayFormUrl expects are relative url to the item that you added to the calendar. In the sample above, I added a url to the News site. If you look at the properties of the hyperlink, you will see this link:

http://cbt/News?ID=

The calendar view automatically adds a querystring parameter ID to your urls. In this case this is not a problem. In the Content By Type webpart however, I add the same links that are generated by the out of the box ContentQuery webpart. These urls look like this:

http://cbt/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=1&ListId={70fbb8db-c7b8-4b32-bf77-f61a13b3e0fc}&WebId={087c3dd8-b0a9-4960-9509-da8887d979b6}&SiteId={9fb94730-cc85-4924-957f-7504f415fe0f}

When you add “?ID=” to that url (that is what the calendar view does), your link will not work and the page will display an “Unknown error“:

calendar02

In the first approach I tried to fix the urls in javascript, but that didn’t work. I was able to trim the “?ID=” bit, but something else kept on adding it back in. I ended up creating a page like the CopyUtil page. When I set the DisplayFormUrl property, I encode the Url that I want to redirect to and add that as a querystring parameter to my redirect page called “tstredirect.aspx”:

string link = /_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=1&ListId={70fbb8db-c7b8-4b32-bf77-f61a13b3e0fc}&WebId={087c3dd8-b0a9-4960-9509-da8887d979b6}&SiteId={9fb94730-cc85-4924-957f-7504f415fe0f}
string urlStart = SPContext.Current.Site.ServerRelativeUrl;
if (urlStart == "/")
    urlStart = string.Empty;
link = string.Format("{0}/_layouts/tst/tstredirect.aspx?GoTo={1}", urlStart, System.Web.HttpUtility.UrlEncode(link));

item.DisplayFormUrl = link;

In that tstredirect page, I decode the querystring GoTo parameter and redirect to that url.

I am not very happy with that last approach, there should be a better way. If you have a suggestion, please let me know. So after all, it still is pretty easy to use the SPCalendarView in your webparts, if you are aware of these things. In the next post I will show you how I exactly implemented it in the Content By Type webpart.

Check permission with:

Name Description
SPSite.DoesUserHavePermissions (SPReusableAcl, SPBasePermissions)
Returns a Boolean value indicates whether the user has permissions for the specified set of rights.
SPSite.DoesUserHavePermissions (SPReusableAcl, SPBasePermissions, SPWeb)
Returns a Boolean value that indicates whether the user has permissions for the specified Web site and set of rights.
Name Description
SPWeb.DoesUserHavePermissions (SPBasePermissions)
Checks permissions of the current user for a specified set of rights and returns a Boolean value.
SPWeb.DoesUserHavePermissions (String, SPBasePermissions)
Checks permissions of the specified user for a specified set of rights and returns a Boolean value.
Name Description
SPList.DoesUserHavePermissions (SPBasePermissions)
Checks the permissions of the current user on the list.
SPList.DoesUserHavePermissions (SPBasePermissions, Boolean)
Checks the permissions of the list, and, optionally. checks the folder permissions.
SPList.DoesUserHavePermissions (SPUser, SPBasePermissions)
Checks the permissions of a specified user on the list.
Name Description
SPListItem.DoesUserHavePermissions (SPBasePermissions)
Checks whether the current user has the specified permissions to an item.
SPListItem.DoesUserHavePermissions (SPUser, SPBasePermissions)
Checks whether a specified user has the specified permissions to an item.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.sppermissioncollection.aspx

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPPermissionCollection collPermissions = oList.Permissions;
    SPUserCollection collUsers = oWebsite.Users;

    foreach (SPUser oUser in collUsers)
    {

        foreach (SPPermission oPermission in collPermissions)
        {

            if (oUser.ID == oPermission.Member.ID)
            {
                 Response.Write("User: " +
                    SPEncode.HtmlEncode(oUser.Name) +
                    " Permissions: " +
                    oPermission.PermissionMask.ToString() +
                    "<BR>");
            }
        }
    }
}
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.sppermission.aspx
SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPPermissionCollection collPermissions = oList.Permissions;
    SPUserCollection collUsers = oWebsite.Users;

    SPMember oMember = collUsers["User_Name"];

    oList.Permissions[oMember].PermissionMask =
        SPRights.AddListItems | SPRights.EditListItems;
}

http://weblogs.asp.net/gunnarpeipman/archive/2008/03/23/how-to-update-sharepoint-list-items-without-creating-new-versions.aspx

SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];item["myField"] = "my value";

item.SystemUpdate(false);
list.Update();

http://msdn.microsoft.com/en-us/library/ms196939.aspx

<And> and <Or> can only be used to compare 2 boolean expressions. Doing otherwise results in a runtime error in Sharepoint Services (described by the ever-helpful “Cannot complete this action. Please try again.” message).

For example, even though the following makes sense as a SQL construct, it will cause Sharepoint to throw an error:

<And>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">Completed</Value>
</Neq>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">5-Closed</Value>
</Neq>
<Eq>
<FieldRef Name="AssignedTo" LookupId="TRUE" />
<Value Type="int">[CurrentUser]</Value>
</Eq>
<Eq>
<FieldRef Name="IsCurrent" />
<Value Type="Boolean">1</Value>
</Eq>
</And>

In order to correctly execute the CAML must be written comparing pairs of values. For example:

<And>
<And>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">Completed</Value>
</Neq>
<Neq>
<FieldRef Name="Status" />
<Value Type="Text">5-Closed</Value>
</Neq>
</And>
<And>
<Eq>
<FieldRef Name="AssignedTo" LookupId="TRUE" />
<Value Type="int">[CurrentUser]</Value>
</Eq>
<Eq>
<FieldRef Name="IsCurrent" />
<Value Type="Boolean">1</Value>
</Eq>
</And>
</And>

 http://sharepointmalarkey.wordpress.com/2008/08/21/sharepoint-internal-field-names/

Title InternalName
$Resources:RulesUrl
$Resources:XomlUrl
% Complete
About Me
Account
Action
Actual Work
Address
All Day Event
Allow writers to view cached content
Anniversary
Append-Only Comments
Approval Status
Approver Comments
Article Date
Assigned To
Assistant’s Name
Assistant’s Phone
Associated Content Type
Associated Service
Attachments
Author
Automatic Update
Base Association Guid
Billing Information
Birthday
Body
Body
Body Was Expanded
Business Phone
Business Phone 2
Byline
Cacheability
Callback Number
Car Phone
Categories
Category
Category
Category
Check for Changes
Check In Comment
Checked out User
Children’s Names
City
Comments
Comments
Company
Company Main Phone
Company Phonetic
Completed
Computer Network Name
Connection Type
Contact
Contact E-Mail Address
Contact Name
Contact Photo
Contact Picture
Content Category
Content Type
Content Type ID
Content Type ID
Contributor
Copy Source
Correct Body To Show
Country/Region
Coverage
Created
Created
Created By
Custom ID Number
Data
Date Completed
Date Created
Date Modified
Date Occurred
Date Picture Taken
Deleted
Department
Department
Description
Description
Description
Discussion Subject
Discussion Title
Display Description
Display Name
Document Created By
Document Modified By
Due Date
Duration
Duration
Duration
Edit
Edit Menu Table End
Edit Menu Table Start
Effective Permissions Mask
E-Mail
E-mail 2
E-mail 3
Email Body
E-Mail Calendar Date Stamp
E-Mail Calendar Sequence
E-Mail Calendar UID
E-Mail Cc
E-Mail From
Email Messages
E-Mail Sender
E-Mail Subject
E-Mail To
Enabled
Encoded Absolute URL
End Date
End Time
Event Address
Event Canceled
Event Type
Event Type
Expires
Extended Properties
External Participant
External Participant Reason
Fax Number
File Size
File Size
File Type
File Type
First Name
First Name Phonetic
Form Category
Form Data
Form Description
Form ID
Form Locale
Form Name
Form Name
Form Relative Url
Form Version
Form_URN
Format
FTP Site
Full Name
FullBody
Gender
Government ID Number
Group Type
GUID
Has Copy Destinations
Has Custom Email Body
Hidden Page
Hobbies
Home Address City
Home Address Country
Home Address Postal Code
Home Address State Or Province
Home Address Street
Home Fax
Home Phone
Home Phone 2
Html File Link
HTML File Type
ID
IM Address
Image Caption
Indentation
Indentation Level
Initials
Instance ID
Is Active
Is Current Version
Is Root Post
Is Signed
Is Site Admin
ISDN
Issue ID
Issue Status
Item Type
Job Title
Keywords
Language
Last Name Phonetic
Last Printed
Last Updated
Less Link
Level
Limited Body
Link
List ID
Location
Manager’s Name
MasterSeriesItemID
Merge
Message ID
Middle Name
Migrated GUID
Mileage
Mobile Phone
Modified
Modified
Modified By
More Link
Name
Name
Name
Name
Name
Nickname
Office
Order
Order
Organizational ID Number
Other Address City
Other Address Country
Other Address Postal Code
Other Address State Or Province
Other Address Street
Other Fax
Other Phone
Outcome
Outcome
owshiddenversion
Page Content
Page Icon
Page Image
Page Layout
Pager
Parent Folder Id
Path
Pending Modification Time
Perform ACL Check
Personal Website
Picture
Picture Height
Picture Size
Picture Width
Post
Posted By
Posted By
Posting Information
Preview
Preview Image
Primary Item ID
Primary Phone
Priority
Profession
ProgId
Property Bag
Published
Publisher
Quoted Text Was Expanded
Radio Phone
Recurrence
Recurrence ID
RecurrenceData
Redirect URL
References
Referred By
Related Company
Related Issues
Relation
Relink
Replies
Reply
Required Field
Resource Identifier
Resource Type
Response
Reusable HTML
Reusable Text
Revision
Rights Management
Role
Rollup Image
Safe for Authenticated Use
Scheduling End Date
Scheduling Start Date
ScopeId
Select
Select
Selection Checkbox
Send Email Notification
Server Relative URL
Shared File Index
Shortest Thread-Index
Shortest Thread-Index Id
Shortest Thread-Index Id Lookup
Show Combine View
Show in Catalog
Show Repair View
SIP Address
Source
Source Name (Converted Document)
Source Url
Source Version (Converted Document)
Spouse
Start Date
State/Province
Status
Status
Style Definitions
Subject
Subject
Subject
Suffix
Summary Links
Summary Links 2
System Task
Target Audiences
Task Group
Task Status
Task Type
Telex
Template Id
Template Link
Thread Index
Thread Topic
Threading
Threading Controls
Thumbnail
Thumbnail URL
TimeZone
Title
Title
Title
Title
Toggle Quoted Text
Total Work
Trimmed Body
TTY-TDD Phone
Type
UDC Purpose
UI Version
UID
Unique Id
URL
URL
URL
URL Path
User Field 1
User Field 2
User Field 3
User Field 4
User ID
Variation Group ID
Variation Relationship Link
Variations
Vary by Custom Parameter
Vary by HTTP Header
Vary by Query String Parameters
Vary by User Rights
Version
Version
Virus Status
Web Image URL
Web Page
Web Preview
Wiki Content
Workflow Association ID
Workflow History Parent Instance
Workflow Instance ID
Workflow Item ID
Workflow List ID
Workflow Name
Workflow Template ID
Workflow Version
Workspace
WorkspaceUrl
XMLTZone
ZIP/Postal Code
RulesUrl
XomlUrl
PercentComplete
Notes
Name
AdminTaskAction
ActualWork
WorkAddress
fAllDayEvent
PublishingCacheAllowWriters
Anniversary
V3Comments
_ModerationStatus
_ModerationComments
ArticleStartDate
AssignedTo
AssistantsName
AssistantNumber
PublishingAssociatedContentType
Service
Attachments
_Author
AutomaticUpdate
BaseAssociationGuid
BillingInformation
Birthday
Body
MessageBody
BodyWasExpanded
WorkPhone
Business2Number
ArticleByLine
PublishingCacheability
CallbackNumber
CarNumber
Categories
_Category
Category
PostCategory
PublishingCacheCheckForChanges
_CheckinComment
CheckoutUser
ChildrensNames
WorkCity
_Comments
Comments
Company
CompanyNumber
CompanyPhonetic
Completed
ComputerNetworkName
ConnectionType
PublishingContact
PublishingContactEmail
PublishingContactName
_Photo
PublishingContactPicture
ContentCategory
ContentType
ContentTypeId
CustomContentTypeId
_Contributor
_CopySource
CorrectBodyToShow
WorkCountry
_Coverage
Created
Created_x0020_Date
Author
CustomerID
Data
DateCompleted
_DCDateCreated
_DCDateModified
Occurred
ImageCreateDate
Deleted
Department
ol_Department
AdminTaskDescription
Comment
DLC_Description
DiscussionTitle
DiscussionTitleLookup
PublishingCacheDisplayDescription
PublishingCacheDisplayName
Created_x0020_By
Modified_x0020_By
TaskDueDate
DLC_Duration
Duration
PublishingCacheDuration
Edit
_EditMenuTableEnd
_EditMenuTableStart
PermMask
EMail
Email2
Email3
EmailBody
EmailCalendarDateStamp
EmailCalendarSequence
EmailCalendarUid
EmailCc
EmailFrom
RelevantMessages
EmailSender
EmailSubject
EmailTo
PublishingCacheEnabled
EncodedAbsUrl
_EndDate
EndDate
ol_EventAddress
EventCanceled
Event
EventType
Expires
ExtendedProperties
OffsiteParticipant
OffsiteParticipantReason
WorkFax
File_x0020_Size
FileSizeDisplay
File_x0020_Type
FileType
FirstName
FirstNamePhonetic
FormCategory
FormData
FormDescription
FormId
FormLocale
FormName
LinkTemplateName
FormRelativeUrl
FormVersion
FormURN
_Format
FTPSite
FullName
FullBody
Gender
GovernmentIDNumber
Group
GUID
_HasCopyDestinations
HasCustomEmailBody
PublishingHidden
Hobbies
HomeAddressCity
HomeAddressCountry
HomeAddressPostalCode
HomeAddressStateOrProvince
HomeAddressStreet
HomeFaxNumber
HomePhone
Home2Number
xd_ProgID
HTML_x0020_File_x0020_Type
ID
IMAddress
PublishingImageCaption
Indentation
IndentLevel
Initials
InstanceID
IsActive
_IsCurrentVersion
IsRootPost
xd_Signature
IsSiteAdmin
ISDNNumber
LinkIssueIDNoMenu
IssueStatus
FSObjType
JobTitle
Keywords
Language
LastNamePhonetic
_LastPrinted
DiscussionLastUpdated
LessLink
_Level
LimitedBody
WorkflowLink
List
Location
ManagersName
MasterSeriesItemID
Combine
MessageId
MiddleName
_PublishingMigratedGuid
Mileage
CellPhone
Last_x0020_Modified
Modified
Editor
MoreLink
BaseName
FileLeafRef
LinkFilename
LinkFilenameNoMenu
NameOrTitle
Nickname
Office
AdminTaskOrder
Order
OrganizationalIDNumber
OtherAddressCity
OtherAddressCountry
OtherAddressPostalCode
OtherAddressStateOrProvince
OtherAddressStreet
OtherFaxNumber
OtherNumber
Outcome
WorkflowOutcome
owshiddenversion
PublishingPageContent
PublishingPageIcon
PublishingPageImage
PublishingPageLayout
PagerNumber
ParentFolderId
FileDirRef
PendingModTime
PublishingCachePerformACLCheck
PersonalWebsite
Picture
ImageHeight
ImageSize
ImageWidth
BodyAndMore
PersonImage
PersonViewMinimal
StatusBar
PreviewOnForm
PublishingPreviewImage
Item
PrimaryNumber
Priority
Profession
ProgId
MetaInfo
PublishedDate
_Publisher
QuotedTextWasExpanded
RadioNumber
fRecurrence
RecurrenceID
RecurrenceData
RedirectURL
EmailReferences
ReferredBy
TaskCompanies
RelatedIssues
_Relation
RepairDocument
ItemChildCount
ReplyNoGif
RequiredField
_Identifier
_ResourceType
AttendeeStatus
ReusableHtml
ReusableText
_Revision
_RightsManagement
Role
PublishingRollupImage
PublishingAuthenticatedUse
PublishingExpirationDate
PublishingStartDate
ScopeId
SelectFilename
SelectTitle
SelectedFlag
SendEmailNotification
ServerUrl
_SharedFileIndex
ShortestThreadIndex
ShortestThreadIndexId
ShortestThreadIndexIdLookup
ShowCombineView
ShowInCatalog
ShowRepairView
SipAddress
_Source
ParentLeafName
_SourceUrl
ParentVersionString
SpouseName
StartDate
WorkState
_Status
DecisionStatus
HeaderStyleDefinitions
LinkDiscussionTitle
LinkDiscussionTitleNoMenu
Subject
Suffix
SummaryLinks
SummaryLinks2
SystemTask
Audience
TaskGroup
TaskStatus
TaskType
TelexNumber
TemplateId
TemplateUrl
ThreadIndex
ThreadTopic
Threading
ThreadingControls
Thumbnail
EncodedAbsThumbnailUrl
TimeZone
LinkTitle
LinkTitleNoMenu
SurveyTitle
Title
ToggleQuotedText
TotalWork
TrimmedBody
TTYTDDNumber
DocIcon
Purpose
_UIVersion
UID
UniqueId
URL
URLNoMenu
URLwMenu
FileRef
UserField1
UserField2
UserField3
UserField4
User
PublishingVariationGroupID
PublishingVariationRelationshipLinkFieldID
PublishingAssociatedVariations
PublishingVaryByCustom
PublishingVaryByHeader
PublishingVaryByParam
PublishingVaryByRights
_UIVersionString
_Version
VirusStatus
EncodedAbsWebImgUrl
WebPage
Preview
WikiField
WorkflowAssociation
WorkflowInstance
WorkflowInstanceID
WorkflowItemId
WorkflowListId
WorkflowName
WorkflowTemplate
WorkflowVersion
WorkspaceLink
Workspace
XMLTZone
WorkZip

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldtype.aspx

 

  Member name Description
  AllDayEvent Specifies an all day event. Corresponds to the SPFieldAllDayEvent class and to the AllDayEvent field type that is specified on the Field element. Value = 29. 
  Attachments Specifies attachments. Corresponds to the SPFieldAttachments class and to the Attachments field type that is specified on the Field element. Value = 19. 
  Boolean Specifies Boolean values that are stored in the database as 1 or 0. Corresponds to the SPFieldBoolean class and to the Boolean field type that is specified on the Field element. Value = 8. 
  Calculated Specifies calculated values. Corresponds to the SPFieldCalculated class and to the Calculated field type that is specified on the Field element. Value = 17. 
  Choice Specifies a predetermined set of values that can be used to enter data into the field. Corresponds to the SPFieldChoice class and to the Choice field type that is specified on the Field element. Value = 6. 
  Computed Specifies an abstract field type that depends on other fields for its content and definition. Corresponds to the SPFieldComputed class and to the Computed field type that is specified on the Field element. Value = 12. 
  ContentTypeId Specifies a content type ID. Corresponds to the ContentTypeId field type that is specified on the Field element. Value = 25. 
  Counter Specifies an integer used for internal ID fields. Corresponds to the Counter field type that is specified on the Field element. Value = 5. 
  CrossProjectLink Specifies a link between projects in a Meetings Workspace site. Corresponds to the SPFieldCrossProjectLink class and to the CrossProjectLink field type that is specified on the Field element. Value = 22. 
  Currency Specifies currency values formatted based on a specific locale. Corresponds to the SPFieldCurrency class and to the Currency field type that is specified on the Field element. Value = 10. 
  DateTime Specifies date and time values. Corresponds to the SPFieldDateTime class and to the DateTime field type that is specified on the Field element. Value = 4. 
  Error Specifies errors. Value = 24. 
  File Specifies files. Corresponds to the SPFieldFile class and to the File field type that is specified on the Field element. Value = 18. 
  GridChoice Specifies a Choice field for a data sheet. Corresponds to the SPFieldRatingScale class and to the GridChoice field type that is specified on the Field element. Value = 16. 
  Guid Specifies GUIDs. Corresponds to the Guid field type that is specified on the Field element. Value = 14. 
  Integer Specifies positive or negative integer values. Corresponds to the Integer field type that is specified on the Field element. Value = 1. 
  Invalid Not used. Value = 0. 
  Lookup Specifies references to values in other lists. Corresponds to the SPFieldLookup class and to the Lookup field type that is specified on the Field element. Value = 7. 
  MaxItems Specifies the maximum number of items. Value = 31. 
  ModStat Specifies Content Approval status. Corresponds to the SPFieldModStat class and to the ModStat field type that is specified on the Field element. Value = 23. 
  MultiChoice Specifies multiple values per list item. Corresponds to the SPFieldMultiChoice class and to the MultiChoice field type that is specified on the Field element. Value = 15. 
  Note Specifies a field that can contain multiple lines of text. Corresponds to the SPFieldMultiLineText class and to the Note field type that is specified on the Field element. Value = 3. 
  Number Specifies floating point numbers. Corresponds to the SPFieldNumber class and to the Number field type that is specified on the Field element. Value = 9. 
  PageSeparator Inserts a page break in a survey list. Corresponds to the SPFieldPageSeparator class and to the PageSeparator field type that is specified on the Field element. Value = 26. 
  Recurrence Specifies a field that is used in calendars for recurring events and abstract field type that, like computed fields, depends on other fields for its content and definition. Corresponds to the SPFieldRecurrence class and to the Recurrence field type that is specified on the Field element. Value = 21. 
  Text Specifies a single line of text. Corresponds to the SPFieldText class and to the Text field type that is specified on the Field element. Value = 2. 
  ThreadIndex Specifies the ID that indicates the relative position of a message within a conversation thread. Corresponds to the ThreadIndex field type that is specified on the Field element. Value = 27. 
  Threading Specifies a field that is used in the creation and display of threaded Web discussions. Corresponds to the Threading field type that is specified on the Field element. Value = 13. 
  URL Specifies hyperlinks. Corresponds to the SPFieldUrl class and to the URL field type that is specified on the Field element. Value = 11. 
  User Specifies users of a SharePoint site. Corresponds to the SPFieldUser class and to the User field type that is specified on the Field element. Value = 20. 
  WorkflowEventType Specifies a workflow event type. Corresponds to the WorkflowEventType field type that is specified on the Field element. Value = 30. 
  WorkflowStatus Specifies workflow status. Corresponds to the SPFieldWorkflowStatus class and to the WorkflowStatus field type that is specified on the Field element. Value = 28. 
SPWeb site = SPControl.GetContextWeb(Context);

string Msg = "";

SPDocDiscussionCollection discs = site.GetDocDiscussions("Document_Library_Name");

foreach (SPDocDiscussion disc in discs)
{
if (disc.CommentCount > 20)
{
Msg = "The file <A href='" + disc.DocUrl.ToString() + "'>" + disc.DocUrl.ToString() +
"</A> has received " + disc.CommentCount.ToString() + " comments.";

SPUtility.SendEmail(site, false, false, "e-mail_address", "Web Discussion Report", Msg);
}
}