Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Webform that feeds into existing list

  Asked By: Madison    Date: Nov 01    Category: Sharepoint    Views: 11730

I wanted to know if I can create a webform on a public portal page and
have it input directly into an existing list.
I am looking to do this without purchasing any additional webparts.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Damini Dande     Answered On: Nov 01

You could write an ASPX web page  containing a form to populate the List
using the Lists.asmx Web Service,

My code may not be most efficient way to do this as am very new to
Programming and is pieced together from different examples I have found
on the Internet, but this seems to work using a public  referral form on
our Public Website that populates a list  on our SharePoint Intranet.

Using Visual Studio, create  a new ASP.Net Web Application in C#

Create a new ASPX Page, for this example will use FeedBack.aspx

Add a Web Reference to the lists.asmx Web Service on your SharePoint
site, for example if your SharePoint site is called
http://intranet.sharepoint.com <http://intranet.sharepoint.com/> use
the following URL

http://intranet.sharepoint.com/_vti_bin/lists.asmx
<http://intranet.sharepoint.com/_vti_bin/lists.asmx>

Name the Web Reference SharePoint.



On the FeedBack.aspx page, create your web form,

For example

Textbox – txtFirstName

Textbox – txtSurname

Textbox - txtTelephoneNumber

Button – btnSubmit



In the FeedBack.aspx.cs file use the following code

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Net;

using System.Xml;

using Microsoft.SharePoint;



namespace PublicForm

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{



}



protected void btnSubmit_Click(object sender, EventArgs e)

{

string Username = "Administrator";

string Password = "Password";

string Domain = "SHAREPOINT";

string ListName = "Test";



Sharepoint.Lists ListsService = new Sharepoint.Lists();

ListsService.Credentials = new NetworkCredential(Username, Password,
Domain);



// Create a new XML document to hold the updates we are
going to perform

XmlDocument doc = new XmlDocument();

XmlElement updates = doc.CreateElement("Batch");

updates.SetAttribute("OnError", "Continue");



// We need to Create a Method Tag for each row we are going
to update.

XmlElement UpdatesMethod = doc.CreateElement("Method");

UpdatesMethod.SetAttribute("ID", "1");

UpdatesMethod.SetAttribute("Cmd", "New");

updates.AppendChild(UpdatesMethod);



// Update the following Fields within the List Item.



XmlElement UpdatesField1 = doc.CreateElement("Field");

UpdatesField1.SetAttribute("Name", "Title");

UpdatesField1.InnerText = " New Application From Public
Website";

UpdatesMethod.AppendChild(UpdatesField1);



XmlElement UpdatesField2 = doc.CreateElement("Field");

UpdatesField2.SetAttribute("Name", "FirstName");

UpdatesField2.InnerText = txtFirstName.Text;

UpdatesMethod.AppendChild(UpdatesField2);



XmlElement UpdatesField3 = doc.CreateElement("Field");

UpdatesField3.SetAttribute("Name", "Surname");

UpdatesField3.InnerText = txtSurname.Text;

UpdatesMethod.AppendChild(UpdatesField3);



UpdatesMethod.AppendChild(UpdatesField1);



XmlElement UpdatesField3 = doc.CreateElement("Field");

UpdatesField3.SetAttribute("Name", "Telephone");

UpdatesField3.InnerText = txtTelephoneNumber.Text;

UpdatesMethod.AppendChild(UpdatesField3);







// Call the web service to update the list items

XmlNode Result = ListsService.UpdateListItems(ListName,
updates);



ListsService.Dispose();



// Send to confimation Page

Response.Redirect("http://www.yourwebsite/thankyou.htm");





}

}

}



You will need to change the following lines of code to match settings
for your SharePoint Site.

string Username = "Administrator";

string Password = "Password";

string Domain = "DEVELOPMENT";

string ListName = "Test";



Also you will need to change match the Column name in the table,for
example the Telephone in red text is the case sensitive name of the
Column in the SharePoint table that I want to populate.



XmlElement UpdatesField3 = doc.CreateElement("Field");

UpdatesField3.SetAttribute("Name", "Telephone");

UpdatesField3.InnerText = txtTelephoneNumber.Text;

UpdatesMethod.AppendChild(UpdatesField3);



Once you have completed the building your form and build project and
publish the ASPX page to your public website.

There are probably a lot more efficient ways of doing this, but I am a
newbie, and this solution worked for me.

 
Didn't find what you were looking for? Find more on Webform that feeds into existing list Or get search suggestion and latest updates.




Tagged: