SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there any way to connect a SharePoint application page to a list in the SharePoint to save data inside form (in application page) to the list in the SharePoint

i need to know it i can make connection code in the application page to connect to the list or if there is another way to do that

share|improve this question

The short answer to your question is yes.

Below is a snippet of one of my application pages, where we tease out the ListID and ItemID that were passed via the URL query string (more on that at Chak's Sharepoint Corner)

Note, in my example page below, I skipped using any ASPX web controls and just emit HTML directly to the response stream. You can altar to do whatever you want, of course. You'll want to implement post-backs and such so as to update a list item I assume.. my un-used 'LoadListVariables' function will at least show you how to get started.

Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.Administration

Namespace AjaxPagelets

    Partial Public Class CommentsFetcher
    Inherits LayoutsPageBase

    Private m_siteID As Guid
    Private m_webID As Guid
    Private m_currentListID As Guid

    Private idForList As String
    Private itemidFromQS As String

    Private specificListItemid As Integer
    Private currentLogList As SPList
    Private currentLogListItem As SPListItem

    Private Sub LoadCommonVariables()
        m_siteID = SPContext.Current.Site.ID
        m_webID = SPContext.Current.Web.ID

        idForList = Request.Params("ListID")
        itemidFromQS = Request.Params("ItemID")

        specificListItemid = 0
        m_currentListID = New Guid(idForList)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        Dim doThis As SPSecurity.CodeToRunElevated
        doThis = AddressOf LoadListVariables



        Response.Write("<html><head><title>" & CStr(currentLogListItem("Title")) & "</title>" & vbCrLf)
        Response.Write("<script type=""text/javascript"">function closeTheWindow(){window.frameElement.commonModalDialogClose(0, 0);}</script>")
        Response.Write("<style>body{font-family:Trebuchet MS;}</style></head><body>" & vbCrLf)
        Response.Write("<br /><a href='javascript:closeTheWindow()'>Close</a>")

    End Sub

    Private Sub LoadListVariables()
        If Int32.TryParse(itemidFromQS, specificListItemid) Then
        Using site As New SPSite(m_siteID)
            Using wb As SPWeb = site.AllWebs(m_webID)
                currentLogList = wb.Lists(m_currentListID)

                currentLogListItem = currentLogList.GetItemById(specificListItemid)

            Catch ex As Exception
                SPDiagnosticsService.Local.WriteTrace(0, New SPDiagnosticsCategory("eSWRC Comments Fetch Failure", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace)
            End Try

            End Using
        End Using
        End If

    End Sub

    Private Sub EmitExceptionResponse(ByVal ex As Exception)
        Response.Write("<html><head><title>There was an error!</title>" & vbCrLf)
        Response.Write("<script type=""text/javascript"">function closeTheWindow(){window.frameElement.commonModalDialogClose(0, 0);}</script>")
        Response.Write("<style>body{font-family:Trebuchet MS;}</style>" & vbCrLf)
        Response.Write(String.Format("</head><body><h1>{0}</h1><h3>{1}</h3><a href='javascript:closeTheWindow()'>Close</a>", ex.Message, ex.StackTrace.Replace(vbCrLf, "<br />")))
        Response.Write(String.Format("<h4>ListID: {0}</h4>{2}<h4>ItemID: {1}</h4>{2} <p>SiteID:{3}</p>{2}<p>WebID: {4}</p>{2}<h2>SPCurrent.ListID: {5}</h2>{2}", idForList, itemidFromQS, vbCrLf, m_siteID, m_webID, m_currentListID))
    End Sub

    End Class

End Namespace

Because my application page is shown within a SharePoint modal dialog, I used a special piece of JavaScript that allows the user to close the dialog correctly, too.

share|improve this answer
I noticed just now your tag 'sharepoint designer' - perhaps I misunderstood what was meant by application pages. My solution has nothing to do with SPD. – bkwdesign Jun 20 '12 at 15:49
Refer to Chak's excellent blog posts on how to launch any custom URL (in the case above, a URL to an .aspx page) and pass in listID and ItemID parameters – bkwdesign Jun 20 '12 at 15:54
first thanks for your reply but i dont understand where should i put this code exaclty this is my code <input type="text" id="txta"/> <input type="text" id="txtb" /> <textarea id="txtarea" cols="10" rows="2">Text area</textarea> <input type="submit" /> </form> </asp:Content> <asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server"> Application Page </asp:Content> – sarah Jun 20 '12 at 16:04
i need to write a code to add the information in this form ,when user insert his information and click submit data sent to share point list – sarah Jun 20 '12 at 16:07

Yes, you definitely can do it.

There are even the special type of controls which could help you in this task: SharePoint Controls.

The idea is that you add some controls on you application page (using aspx file or code-behind), set several fields of these controls like FieldName, ListId, ItemId, ControlMode (New, Edit, Display) and after that this control is connected to the list that you connect it to. So,

  • if you set ControlMode to Edit (or Display for readonly) when you open this application page, you will see value of necessary field this control is connected to (using ListId and ItemId);
  • if ControlMode is New (that you need), then after submitting this page using <SharePoint:SaveButton runat="server" ControlMode="New"/> a new item will be added in the list controls connected to.

You can have something similar in you aspx file:

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <SharePoint:FormField id="NameField" runat="server" FieldName="Name" ControlMode="New"/>
    <SharePoint:FormField id="TitleField" runat="server" FieldName="Title" ControlMode="New"/>
    <SharePoint:SaveButton runat="server" ControlMode="New"/>
    <SharePoint:GoBackButton runat="server" ControlMode="New"/>

As your control should be connected to some list, you should change context of it. You can do it in your code-behind:

protected override void OnInit(EventArgs e)
       using (SPSite site=SPContext.Current.Site){
          using (SPWeb web = _list.ParentWeb)
               SPContext renderContext = SPContext.GetContext(this.Context, 0, _list.ID, web);
               NameField.RenderContext = renderContext;
               NameField.ItemContext = renderContext;
               TitleField.RenderContext = renderContext;
               TitleField.ItemContext = renderContext;

Probably part of code shown above has some issues (I didn't test it), but I think you have to take a look at the way of SharePoint controls. If proposed solution doesn't work for you, don't hesitate to let us know and I will improve my answer.

Some links, which could be usefull:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.