Tuesday, March 25, 2014

How to create form in Visual Studio to replace Infopath?

You need to develop a visual web part using Visual Studio 2010/2013. In visual web part, add all fields related to your form and brand it as per your requirement. Once you complete visual web part, deploy it your SharePoint site (Dev environment first), and after that create a New Page in Pages library (or site pages). Add your web part on the page and publish it if required.


Submit data using this custom developed form instead of infopath.


Add new item code will be like



SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists["List Name"].Items;

SPListItem item = listItems.Add();

item["Title"] = txtTitle.Text;
item["Stock"] = Convert.ToInt32(txtStock.Text);
item["Return Date"] = Convert.ToDateTime(TextBox4.Text);
item["Employee"] = TextBox5.Text;

item.Update();
}

Below link shows how to create and deploy a visual web part in SharePoint.


Create Visual Web Parts in SharePoint 2010




Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :)


No comments:

Post a Comment