Thursday, August 25, 2011

Create Custom Activity Workflow

  1. Open Visual Studio
  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 CorrespondanceEmailActivities(any project name), and then click OK.
  5. Rename Activity1 to EmailActivity1. (any project name)
  6. 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 EmailActivity1: Activity
      { …
      1. Now you must create some Dependency Properties. Add the following fields inside your class definition.
      2. public static DependencyProperty ToProperty
              = DependencyProperty.Register(
                  "To", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty FromProperty
              = DependencyProperty.Register(
                  "From", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty CCProperty
              = DependencyProperty.Register(
                  "CC", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty SubjectProperty
              = DependencyProperty.Register(
                  "Subject", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty BodyProperty
              = DependencyProperty.Register(
                  "Body", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty AttachmentProperty
              = DependencyProperty.Register(
                  "Attachment", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty SmtpServerProperty
              = DependencyProperty.Register(
                  "SmtpServer", typeof(string), typeof(EmailActivity1));
            public static DependencyProperty InvokeEvent
              = DependencyProperty.Register(
                  "Invoke", typeof(EventHandler), typeof(EmailActivity1));
         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.
      1. 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(EmailActivity1.ToProperty))); }
              set { base.SetValue(EmailActivity1.ToProperty, value); }
           }
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
           [ValidationOption(ValidationOption.Required)]
           [Browsable(true)]
           [Description("Enter the e-mail sender")]
           public string From
           {
              get { return ((string)(base.GetValue(EmailActivity1.FromProperty))); }
              set { base.SetValue(EmailActivity1.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(EmailActivity1.CCProperty))); }
             set { base.SetValue(EmailActivity1.CCProperty, value); }
          }
          [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
          [ValidationOption(ValidationOption.Required)]
          [Browsable(true)]
          [Description("Enter the e-mail subject")]
          public string Subject
          {
             get { return ((string)(base.GetValue(EmailActivity1.SubjectProperty))); }
             set { base.SetValue(EmailActivity1.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(EmailActivity1.BodyProperty))); }
              set { base.SetValue(EmailActivity1.BodyProperty, value); }
           }
           [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
           [ValidationOption(ValidationOption.Optional)]
           [Browsable(true)]
           [Description("Enter an attachment file path")]
           public string Attachment
           {
              get { return ((string)(base.GetValue
                (EmailActivity1.AttachmentProperty))); }
              set { base.SetValue(EmailActivity1.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
                (EmailActivity1.SmtpServerProperty))); }
              set { base.SetValue(EmailActivity1.SmtpServerProperty, value); }
           }
      1. 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(EmailActivity1.InvokeEvent, value);
            }
            remove
            {
               base.RemoveHandler(EmailActivity1.InvokeEvent, value);
            }
         }
      1. Add a using statement at the top of the class. This enables you to access the ASP.NET Mail namespace for sending your e-mail message. Add the following code.
      using System.Net.Mail;
      1. 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(EmailActivity1.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 as shown below.
Below are shown steps which you should follow whenever first time custom activity workflow is created and also whenever any change is done in custom activity workflow application file.
Go to application –make changes
Then click properties of solution file and create strong name as shown-

    Click ok and build application

    Deploy assembly to GAC

    If assembly is CorrespondanceEmailActivities.dll then go to project folder->bin->Debug -> CorrespondanceEmailActivities.dll
    Right click on assembly dll file and in properties copy path of it. Like as below-
    C:\Project\CorrespondanceEmailActivities\CorrespondanceEmailActivities\bin\Debug
    Open Visual studio command prompt and run below commands-
    cd C:\Project\CorrespondanceEmailActivities\CorrespondanceEmailActivities\bin\Debug
    gacutil /if CorrespondanceEmailActivities.dll
    sn -T CorrespondanceEmailActivities.dll
    it will generate public key token just copy that key.
    <authorizedType Assembly="CorrespondanceEmailActivities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cbf3c65e6ac8e98e" Namespace="CorrespondanceEmailActivities" TypeName="*" Authorized="True" />
    . go to ->C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\Workflow
    Copy public key token in txt file and save.

Create Document Sets

Configure outgoing e-mail from Central Administrator

    

1.     Verify that you have the following administrative credentials: You must be a member of the Farm Administrators group on the computer that is running the SharePoint Central Administration Web site.
2.     In Central Administration, click System Settings.
3.     On the System Settings page, in the E-Mail and Text Messages (SMS) section, click Configure outgoing e-mail settings.
4.     On the Outgoing E-Mail Settings page, in the Mail Settings section, type the SMTP server name for outgoing e-mail (for example, mail.example.com) in the Outbound SMTP server box.
5.     In the From address box, type the e-mail address as you want it to be displayed to e-mail recipients.
6.     In the Reply-to address box, type the e-mail address to which you want e-mail recipients to reply.
7.     In the Character set list, select the character set that is appropriate for your language.
8.     Click OK.
Select Yes option radio button for Enable Incoming Email in screenshot above and click ok.
Now finally check for Emails working

Create External List from SharePoint Site rather than SharePoint designer


Monday, August 1, 2011

Can't Open PDFs in SharePoint 2010

If you have your nice SP2010 setup you may notice that when you go to open a PDF file it prompts you to save it rather than opening.
Never fear there is a solution. It’s in central admin.
Go there and click ‘Manage Web Applications’
Click on the web app you want to change, and go to ‘General Settings’
Scroll down the list until you reach ‘Browser File Handling’
Change the radio box from Strict to Permissive.