IT tutorials
 
Applications Server
 

SharePoint Applications Using Windows Azure : Create a SharePoint List and Add an Event Receiver That Calls a Windows Azure WCF Service

12/4/2012 11:33:37 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Create a SharePoint List and Add an Event Receiver That Calls a Windows Azure WCF Service

  1. Return to the Visual Studio solution and right-click it. Select Add and then click New Project.

  2. Add an Empty SharePoint Project, provide a name for the project (such as ListAndEventReceiver), select Deploy As A Farm Solution, and click Finish.

  3. Add the service reference similar to the WCF Windows Azure service by right-clicking the project and selecting Add Service Reference. Add the Windows Azure service endpoint URI in the Address field. Click Go, and then when the service is loaded, provide a namespace for the service (for example, AzureMortgageService).

  4. Right-click the new SharePoint project and select Add | New Item.

  5. Select List Definition and provide a name (such as Mortgages), as shown in the following graphic.

    image with no caption
  6. Click Add. Rename the default ListInstance1 to MortgagesList. In the new solution, you’ll see two instances of Elements.xml as shown in the following graphic. Navigate to the Elements.xml within MortgagesList and double-click it to open it.

    image with no caption
  7. Amend this first Elements.xml so it looks like the following code listing:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="Mortgages"
                    OnQuickLaunch="TRUE"
                    TemplateType="10001"
                    Url="Lists/MortgagesList"
                    Description="List that stores information about mortgage customers and
                                 rates.">
      </ListInstance>
    </Elements>
  8. Amend the second Elements.xml file (under Mortgages) so it looks like the code here:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Field Type="Text" DisplayName="Offering" Required="FALSE"
             NumLines="6" RichText="FALSE" Sortable="FALSE"
             ID="{3A811B2A-EEF5-44A7-BB5F-0E925A53D6CE}"
             StaticName="Offering" Name="Offering"
             Group="Custom Columns" />
      <Field Type="Text" DisplayName="Rate" Required="FALSE"
             MaxLength="255" ID="{78089CAD-A90C-42F1-8240-E8EFD2CA7191}"
             StaticName="Rate" Name="Rate"
             Group="Custom Columns" />
      <Field Type="Text" DisplayName="APR" Required="FALSE"
             MaxLength="255" ID="{7D4CC8E4-C7A7-486E-8185-E07BA646CAE6}"
             StaticName="APR" Name="APR"
             Group="Custom Columns" />
      <ContentType ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" Name="Mortgage Record"
        Group="Mortgages" Description="Mortgage content type." Version="0">
        <FieldRefs>
          <FieldRef ID="{3A811B2A-EEF5-44A7-BB5F-0E925A53D6CE}" />
          <FieldRef ID="{78089CAD-A90C-42F1-8240-E8EFD2CA7191}" />
          <FieldRef ID="{7D4CC8E4-C7A7-486E-8185-E07BA646CAE6/>
        </FieldRefs>
      </ContentType>
      <ListTemplate
            Name="Mortgages"
            Type="10001"
            BaseType="0"
            OnQuickLaunch="TRUE"
            SecurityBits="11"
            Sequence="410"
            DisplayName="Mortgages"
            DisallowContentTypes="FALSE"
            Description=
              "List that provides information on customers and current mortgage rates."
            Image="/_layouts/images/itgen.png"/>
    </Elements>
  9. Open the Schema.xml file and amend the code in the file as per the bolded code shown here:

    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ows="Microsoft SharePoint" Title="Mortgages" EnableContentTypes="TRUE"
    FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Mortgages"
    BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
      <MetaData>
        <ContentTypes>
          <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />
          <ContentTypeRef ID="0x01">
            <Folder TargetName="Item" />
          </ContentTypeRef>
          <ContentTypeRef ID="0x0120" />
        </ContentTypes>
        <Fields>
          <Field Type="Text" DisplayName="Offering" Required="FALSE"
           NumLines="6" RichText="FALSE" Sortable="FALSE"
           ID="{3A811B2A-EEF5-44A7-BB5F-0E925A53D6CE}"
           StaticName="Offering" Name="Offering"
           Group="Custom Columns" />
          <Field Type="Text" DisplayName="Rate" Required="FALSE"
                 MaxLength="255" ID="{78089CAD-A90C-42F1-8240-E8EFD2CA7191}"
                 StaticName="Rate" Name="Rate"
                 Group="Custom Columns" />
          <Field Type="Text" DisplayName="APR" Required="FALSE"
                 MaxLength="255" ID="{7D4CC8E4-C7A7-486E-8185-E07BA646CAE6}"
                 StaticName="APR" Name="APR"
                 Group="Custom Columns" />
       </Fields>
        <Views>
          <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="LinkTitleNoMenu"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="AddNewAnnouncement"
                Location="Resource(wss,addnewitem)" />
              <ParameterBinding Name="NoAnnouncements"
                Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo"
                Location="Resource(wss,noXinviewofY_ONET_HOME)" />
            </ParameterBindings>
          </View>
          <View BaseViewID="1" Type="HTML" WebPartZoneID="Main"
            DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;"
            DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE"
            SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png"
            Url="AllItems.aspx">
            <Toolbar Type="Standard" />
            <XslLink Default="TRUE">main.xsl</XslLink>
            <RowLimit Paged="TRUE">30</RowLimit>
            <ViewFields>
              <FieldRef Name="Attachments"></FieldRef>
              <FieldRef Name="LinkTitle"></FieldRef>
              <FieldRef Name="Offering"></FieldRef>
              <FieldRef Name="Rate"></FieldRef>
              <FieldRef Name="APR"></FieldRef>
            </ViewFields>
            <Query>
              <OrderBy>
                <FieldRef Name="ID"></FieldRef>
              </OrderBy>
            </Query>
            <ParameterBindings>
              <ParameterBinding Name="NoAnnouncements"
                 Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo"
                 Location="Resource(wss,noXinviewofY_DEFAULT)" />
            </ParameterBindings>
          </View>
        </Views>
        <Forms>
          <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx"
             WebPartZoneID="Main" />
          <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx"
             WebPartZoneID="Main" />
          <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx"
             WebPartZoneID="Main" />
        </Forms>
      </MetaData>
    </List>
  10. Now that you’ve completed the list definition, right-click the SharePoint project and select Add | New Item.

  11. Select the Event Receiver, provide a name (such as MortgageRecordEvent), and click Add.

  12. When prompted, select List Item Events as the type of event receiver and the MortgagesList list as the event source. Select the An Item Is Being Added check box as the event to trap. The following graphic illustrates these options.

    image with no caption
  13. When the event receiver has been added to the project, double-click the event receiver class file and amend the code, as per the bolded text here:

    using System;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Security;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Workflow;
    using ListAndEventReceiver.AzureMortgageService;
    
    namespace ListAndEventReceiver.MortgageRecordEvent
    {
        public class MortgageRecordEvent : SPItemEventReceiver
        {
           public override void ItemAdded(SPItemEventProperties properties)
           {
                   this.EventFiringEnabled = false;
                   LogMortgageRecord(properties);
                   this.EventFiringEnabled = true;
           }
           private void LogMortgageRecord(SPItemEventProperties properties)
           {
               AzureServiceClient myAzureSvc = new AzureServiceClient();
               double[] returnProductInfoFromAzure = new double[6];
               returnProductInfoFromAzure = myAzureSvc.getDailyInterestRate();
               double returnProductCosts = returnProductInfoFromAzure[0];
               double mortgageAPR = .18 * 100;
               string mortgageOffering = "30 YR Fixed";
               double dblDailyInterestRate = 0.13;
               returnProductCosts = dblDailyInterestRate += .24 * 100;
    
               string mySPSite = "http://blueyonderdemo";
    
               using (SPSite site = new SPSite(mySPSite))
               {
                   using (SPWeb web = site.OpenWeb())
                   {
                       web.AllowUnsafeUpdates = true;
                       SPList mortgageList = web.GetList("Lists/MortgagesList");
    
                       SPQuery myCAMLQuery = new SPQuery();
                       myCAMLQuery.Query = "<Query>" +
                                               "<Where><Eq>" +
                                                   "<FieldRef Name='Title'></FieldRef>" +
                                                       "<Value Type='Text'>Contoso
    </Value>" +
                                               "</Eq></Where></Query>";
    
                       SPListItemCollection collItem = mortgageList.GetItems(myCAMLQuery);
    
                       foreach (SPListItem oItem in collItem)
                       {
                           if (oItem["Title"].ToString() == "Contoso")
                           {
                               oItem["Offering"] = mortgageOffering;
                               oItem["Rate"] = returnProductCosts.ToString() + "%";
                               oItem["APR"] = mortgageAPR.ToString() + "%";
                               oItem.Update();
                           }
                       }
                       web.AllowUnsafeUpdates = false;
                   }
               }
           }
        }
    }

    When it finds that list item, the code updates three fields by first creating a collection of items (collItem) and then iterating through each item and filling in Offering, Rate and APR:

    ...
    
    SPQuery myCAMLQuery = new SPQuery();
    myCAMLQuery.Query = "<Query>" +
      "<Where><Eq>" +
      "<FieldRef Name='Title'></FieldRef>" +
      "<Value Type='Text'>Contoso</Value>" +
      "</Eq></Where></Query>";
    
      SPListItemCollection collItem = mortgageList.GetItems(myCAMLQuery);
    
    ...

    The Update method then updates the list. You might recognize that you are using the SharePoint server object model to interact with the list and add the data retrieved from the Windows Azure WCF service endpoint.

  14. When done, press F6 to build the project to ensure that there are no errors.

  15. Next, right-click the project and select Deploy.

  16. After the project has deployed successfully, you can navigate to the new list and add a single record where the title is Contoso. Adding the new list item triggers a call to the WCF service and then updates the three fields with values calculated from the data returned from the service. The following graphic shows the result of this service call.

image with no caption

Creating an event receiver might not be something you do every day, but it can be useful. In this exercise, you built a custom list instance and then created a custom event receiver that updated a list item (or record) using data retrieved from the Windows Azure service.

 
Others
 
- SharePoint Applications Using Windows Azure : Create and Deploy a Silverlight Web Part That Consumes the WCF Service
- Administering Active Directory Domain Services : Delegation and Security of Active Directory Objects (part 2)
- Administering Active Directory Domain Services : Delegation and Security of Active Directory Objects (part 1)
- Microsoft Dynamics AX 2009 : Creating configuration documents using Word
- Microsoft Dynamics AX 2009 : Creating Word documents from templates
- SharePoint Applications Using Windows Azure : Create a Web Part That Uses the Windows Azure WCF Service
- SharePoint Applications Using Windows Azure : Create a WCF Service and Deploy It to Windows Azure
- Deploying Exchange Server 2010 : Integrating Exchange Server Roles with Active Directory
- Deploying Exchange Server 2010 : Exchange Server Messaging Roles
- SharePoint 2010: Performing Backups and Restores (part 3) - Example of Performing a SharePoint 2010 Farm Backup and Restore
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us