Finally, I was able to finish the second part of the post about SharePoint 2010 application pages. First part can be found here. At the end of the previous post you saw that for the new item we need a page for it. In my case, it’s “WorkFlow01_New.aspx”. Of course, we can imagine that the same form will be used for all tasks, but it could be to complicated and messy. Anyway, we add a new application page to the project and then we place it into “PlaceHolderMain” module following controls: 5 labels, 4 text fields, 1 calendar control, and a button. The tricky part is that we don’t have access to the graphic designer of VSTO, so we can’t see our design of the page in the fly. See below my simple page. As you can see there’s nothing fancy.

<asp:ContentID=”PageHead”ContentPlaceHolderID=”PlaceHolderAdditionalPageHead”runat=”server”>

</asp:Content>

 

<asp:ContentID=”Main”ContentPlaceHolderID=”PlaceHolderMain”runat=”server”>

<tablewidth=”1000″>

<tr>

<td><asp:LabelID=”LbInvoiceNumber”runat=”server” Text=”InvoiceNumber”> </asp:Label></td>

<td><asp:LabelID=”LbInvoiceDate”runat=”server”Text=”InvoiceDate”>

</asp:Label></td>

<td><asp:LabelID=”LbInvoiceAmount”runat=”server”Text=”InvoiceAmount”>

</asp:Label></td>

<td><asp:LabelID=”LbSupplier”runat=”server”Text=”Supplier”>

</asp:Label></td>

<td><asp:LabelID=”LbPurchaseOrder”runat=”server”Text=”PurchaseOrder”>

</asp:Label></td>

</tr>

  

<tr>

    <td><asp:TextBoxID=”InvoiceNumber”runat=”server”></asp:TextBox></td>

    <td><asp:CalendarID=”InvoiceDate”runat=”server”></asp:Calendar></td>

    <td><asp:TextBoxID=”InvoiceAmount”runat=”server”></asp:TextBox></td>

    <td><asp:TextBoxID=”Supplier”runat=”server”></asp:TextBox></td>

    <td><asp:TextBoxID=”PurchaseOrder”runat=”server”></asp:TextBox></td>

</tr>

</table>

<asp:ButtonID=”SaveToList”runat=”server”Text=”Save to list”OnClick=”SaveList”on/>

 

</asp:Content>

 

<asp:ContentID=”PageTitle”ContentPlaceHolderID=”PlaceHolderPageTitle”runat=”server”>

Application Page

</asp:Content>

 

<asp:ContentID=”PageTitleInTitleArea”ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea”runat=”server”>

My Application Page

</asp:Content>

image

Now it’s time to create a method to send data to the list. When you use the application page all behaviors depend on you, so without that the button will be useless. As you see in the code of the page, I put already OnClick method into button control. The method code is below:

protectedvoid SaveList(object sender, EventArgs e)

        {

        

            SPList list = SPContext.Current.Web.Lists.TryGetList(“Financial Workflow List”);

           

            SPListItem newItem = list.Items.Add();

            newItem[“InvoiceNr”]=InvoiceNumber.Text.ToString() ;

            newItem[“InvoiceDt”]=InvoiceDate.SelectedDate ;

            newItem[“InvoiceAm” ]=InvoiceAmount.Text ;

            newItem[“Supplier” ]=Supplier.Text.ToString ();

            newItem[“PurchaseOrder”]=PurchaseOrder.Text.ToString()  ;

            newItem.Update();

         

            HttpContext context = HttpContext.Current;

               if (HttpContext.Current.Request.QueryString[“IsDlg”] != null)

                {

                    context.Response.Write(“<script type=’text/javascript’>window.frameElement.commitPopup()</script>”);

                       context.Response.Flush();

                       context.Response.End();

                       }              

                }

    }

Ok, so what do we do? The first part of the code creates an instance of our list. Then we assign values of our controls to proper columns of the list. And after that, we finally call Update() method to put data on the list. In the end, we have to remove the application page from the screen. Also this last part of the code refresh content of our list.

And that’s all. I’ll try to create the next part of the series “Application pages” and present how we can place there additional functionality.