How to create and publish InfoPath in SharePoint 2013

Anne Jes Medon
 
SharePoint Developer
April 6, 2013
 
Rate this article
 
Views
65342

InfoPath is helpful to create Reports in SharePoint 2013. This article describes how to create an InfoPath Form and Publish Report using SharePoint 2013.

Create a list and a document library in your site collection. Create a list is for creating items and Document Library is for saving the documents/Reports.

Step 1:

Open SharePoint and create new list. Click Customise Form from Ribbon, which opens to InfoPath designer.

image

Step 2:

Add a table from custom table of File Ribbon or you can make your own Reports from MS-Word to InfoPath

image

Delete Title and attachments table, whereas uncheck the required validator for Title in the field.

Step 3:

Add Fields from the Controls Ribbon, corresponding to your requirement and right click fields to change the Properties name.

image

Step 4:

After adding the fields, add button for saving the data from InfoPath to Library/List and click the Control Properties.

image

Step 5:

Select Submit from Action Dropdown, then proceed to Submit Options button. Select SharePoint doc Library from the dropdown and click Add.

image

Step 6:

This will take to Data Connection Wizard and provide the Document library URL into it.

image

Step 7:

Give the name of the form and finish.

Step 8:

Go to file menu and click Publish.

Step 9:

The page redirects to the SharePoint list page and add new item to your report and submit.

Step 10:

Now click the Reports Document library from the Quick launch, you can see the document that saved in to the Document Library.

image

Step 11:

The final output will be as below

image

Category : Infopath, SharePoint

Author Info

Anne Jes Medon
 
SharePoint Developer
 
Rate this article
 
Works as SharePoint Developer in Chennai, India. ...read more
 

How to Create a Site Column in SharePoint 2010

Gopal Muthukrishnan
 
SharePoint Developer
February 19, 2013
 
Rate this article
 
Views
31038

This article describes how to create a site column in SharePoint 2010 by using SharePoint UI, Programmatically, PowerShell and SharePoint Designer. By this, you can choose your own choice to create a Site Column in your environment.

Site column

SharePoint 2010 has a site column entity that allows you to reuse columns across multiple lists.  If you create a new column in custom List, you can use the column in that list alone. Suppose if you create a site column you can use the column in any list or library within your Team Site

1. Create Site Column in SharePoint UI

2. Programmatically create Site column

3. Create Site Column by PowerShell

4. Create Site Column by SharePoint Designer

To create a new site column in a list or library

Step 1:-

Choose Site Actions

clip_image001

Step 2:-

Click Site Settings from Site Actions from Top Level Site

clip_image003

Step 3:-

Click the Site Columns from Galleries

clip_image005

Step 4:-

Click the Create link to create a new column.

 clip_image007

Step 5:-

Enter the name for your site column in Column Name field.

Step 6:-

Select the column type by clicking the radio button.

Step 7:

Then Select Custom Column from Existing groups dropdown. This site column must be a member of this group.

clip_image009

Step 8:-

Click OK button. Your site column will be listed in site columns.

 

Programmatically create Site Column in SharePoint

Adding a New Site Column in SharePoint Site

 SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    SPWeb web = site.RootWeb;
                    //Create Site Column
                    string SiteColumnName = "India";
                    //Add choice Field "India"
                    if (!web.Fields.ContainsField(SiteColumnName))   
                    {
                        string countryField = web.Fields.Add(SiteColumnName, SPFieldType.Choice, false);
                        //Set the Field Properties
                        SPFieldChoice CityInIndia = (SPFieldChoice)web.Fields.GetField(SiteColumnName);
                        //Set the group for the Site column
                        CityInIndia.Group = "States";    
                        //Add the choices
                        string[] States = new string[] { "TamilNadu", "Kerala", "Andhra Pradesh", "karnataka"};
                        CityInIndia.Choices.AddRange(States);
                        //Set the default value
                        CityInIndia.DefaultValue = "TamilNadu";
                        //Set Fillable value
                        CityInIndia.FillInChoice = true;
                        //Update the field
                        CityInIndia.Update();
 
                    }
                }
            });

Create a New Site column by PowerShell

Code for creating a New site Column through PowerShell Script

 $site = Get-SPSite -Identity "http://sfs03-pc:12121/sites/Samples/"
 $web = $site.RootWeb 
 $fieldXML = '<Field Type="Text"
 Name="EmpName"
 Description="Employee Name Column Info."
 DisplayName="EmpName"
 Group="EmployeeInformation"
 Hidden="FALSE"
 Required="FALSE"
 ShowInDisplayForm="TRUE"
 ShowInEditForm="TRUE"
 ShowInListSettings="TRUE"
 ShowInNewForm="TRUE"></Field>' 
 $web.Fields.AddFieldAsXml($fieldXML)
 $web.Dispose()
 $site.Dispose()

Then check your Gallery you will find the site column in the name of EmpName under the group of EmployeeInformation

Modifying the Existing Site column by PowerShell

Code for Modifying the Existing site Column through PowerShell Script

$site = Get-SPSite -Identity "http://sfs03-pc:12121/sites/Samples/"
$web = $site.RootWeb 
$field=$web.Fields["EmpName"]
$field.Type= "Choice"
$field.Update($true)
$web.Dispose()
$site.Dispose()

Then check your Gallery, EmpName column type will change to Choice type

Create a new site column in Sharepoint Designer

Open your Site in Microsoft SharePoint Designer

Step 1:-

Click Site Columns

clip_image001[4]

Step 2:-

Click the New Column from file Menu and the choose its Type

clip_image002

Step 3:-

Enter The Column Name in the TextBox and the Choose group

clip_image003

Step 4:-

Click save Button to find your Created SiteColumn

clip_image004

Author Info

Gopal Muthukrishnan
 
SharePoint Developer
 
Rate this article
 
Works as SharePoint Developer in Chennai, India. ...read more
 

Creating Business Data Connectivity Service and External Content Type using SharePoint Designer 2010

Mohamed Sithik
 
SharePoint Consultant
 
Rate this article
 
Views
39857

This article shows how to create a Business Data Connectivity using external Content type through SharePoint Designer. Business Data Connectivity can be used to integrate with SQL database and SharePoint in your working scenario to manage data’s using SQL Server.

Step 1:

Open SQL Server and create a database named “Employee”. Then create a table named “EmpInfo” and create a column as show in a figure below

clip_image001

Step 2:

Go to Central Administration and click Manage Service application

clip_image003

Step 3:

Click the New button from menu, list of services will be listed. Then click the Business Data Connectivity services and configure them.

clip_image005

Step 4:

After connecting the Business Data Connectivity services. Open SharePoint Designer and click Central Administration

clip_image007

Step 5:

Click the External Content Types from the left menu

clip_image009

Step 6:

Click New External Content Types from the file menu

clip_image011

Step 7:

Click here to discover external data sources and define operations for connecting the external data source shown below

clip_image013

Step 8:

Add Connection button to connect the SQL Server

clip_image015

Step 9:

Choose the Data Source Type as SQL Server

clip_image017

Step 10:

Configure SQL Server as below and click ok

clip_image019

Step 11:

Now the SQL Server is connected and you will get the Employee Database connection Source

clip_image021

Step 12:

Click Table name Emp -> Tables ->EmpInfo then right click the EmpInfo and click the Create All operations

clip_image023

Step 13:

Then All operation will popped up. Click Next button

clip_image025

Step 14:

Parameter Configuration popped up and click Finish Button

clip_image027

Step 15:

Click Create Lists & Form Icon from Ribbon

clip_image029

Step 16:

Then Conformation Will be popped up and give “Yes” to save the changes

clip_image031

Step 17:

Enter List Name as Employee information and click ok button

clip_image033

Step 18:

Go to Central Administration

Click Site Actions->View All Site Content and EmployeeInformation will be listed there.

clip_image035

Step 19:

Click the New button from the menu

clip_image037

Step 20:

Add New item and Save it

clip_image039

 

clip_image041

Step 21:

Open SQL Server ->Choose the Database “Employee” and Check the “Emplnfo” table using Query analyser. Your data will be saved.

clip_image043

Category : SharePoint

Author Info

Mohamed Sithik
 
SharePoint Consultant
 
Rate this article
 
SharePoint Consultant based out Chennai, India. ...read more
 

Custom List definition and List Form with Content Type Inheritance in SharePoint 2010

Gopal Muthukrishnan
 
SharePoint Developer
December 21, 2012
 
Rate this article
 
Views
26863

In this blog post we can see how to create a custom List definition and also how to create a custom Add and Edit form for a SharePoint List in SharePoint 2010.In this demo application I have created a list with two different content types namely Permanent Employee and Contract Employee. Then created a Custom form for list definition without using List Instance and I have demonstrated how to create our own custom add,edit and cancel using submit form .

Step:1

Open Visual Studio 2010 and create a new EMPTY Share point project located under SharePoint2010 category and name it as ListDefUsingCTypes then click ok to proceed for further step.

sharepoint_newprj

Step 2:

Give the URL of the project that you have created in your SharePoint environment and click validate to ensure that you are able to connect your SharePoint environment. Select Farm solution and click finish

validate

Step:3

Add new item(select List Definiton) in the solution explorer and name as ListDef-TwoCTypes and click Add

List_newpj

STEP 4:

Then select the custom list type of List definition in the dropdown list and uncheck the list instances. Click Finish

List_confgWiqard

Step5:

To modify the list definition Elements.xml file

· In Solution Explorer, under the ListDef-TwoCTypes node, open the Elements.xml file. Replace the contents of the ListDef-TwoCTypes\Elements.xml file with the following markup.

· Add this tag inside DisallowContentTypes="FALSE" in the ListTemplate tag

 <?xml version="1.0" encoding="utf-8"?>
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Field ID="{AD2E49DD-0F22-41DF-A6E6-143DA4233A00}" Name="EmpName" DisplayName="EmpName"
         Type="Text" Required="TRUE" Sealed="TRUE"></Field>
   <Field ID="{3836280D-B224-4EB9-B828-825D604F29CE}" Name="Age" DisplayName="Age"
          Type="Number" Required="TRUE" Sealed="TRUE"></Field>
   <Field ID="{13742AE8-8D25-4489-BE21-D096A857005B}" Name="Address" DisplayName="Address"
          Type="Note" Required="TRUE" Sealed="TRUE"></Field>
   <Field ID="{9C058F10-4CA0-42B3-9362-BE7A37BD83BE}" Name="Experience" DisplayName="Experience"
          Type="Number" Required="TRUE" Sealed="TRUE"></Field>
   <Field ID="{0A33F782-B1FF-4F6C-8CF4-A24D8F28B3B8}" Name="VendorCompany" DisplayName="VendorCompany"
          Type="Note" Required="TRUE" Sealed="TRUE"></Field>
   <ContentType ID="0x01009A0146B37A4D43E4B938F14E10DD0872" Name="PermentEmployee" Group="Employee">
     <FieldRefs>
       <FieldRef ID="{AD2E49DD-0F22-41DF-A6E6-143DA4233A00}"/>
       <FieldRef ID="{3836280D-B224-4EB9-B828-825D604F29CE}"/>
       <FieldRef ID="{13742AE8-8D25-4489-BE21-D096A857005B}"/>
       <FieldRef ID="{9C058F10-4CA0-42B3-9362-BE7A37BD83BE}"/>
     </FieldRefs>
   </ContentType>
   <ContentType ID="0x0100CB33B794B1E0466DBE8EA398204F699C" Name="ContractEmployee" Group="Employee">
     <FieldRefs>
       <FieldRef ID="{AD2E49DD-0F22-41DF-A6E6-143DA4233A00}"/>
       <FieldRef ID="{3836280D-B224-4EB9-B828-825D604F29CE}"/>
       <FieldRef ID="{13742AE8-8D25-4489-BE21-D096A857005B}"/>
       <FieldRef ID="{0A33F782-B1FF-4F6C-8CF4-A24D8F28B3B8}"/>
     </FieldRefs>
   </ContentType>

Step: 6

To modify the schema.xml file

· In Solution Explorer, under the ListDefinition1 node, open the Schema.xml file. Replace the content of the ListDefinition1\Schema.xml file with the following markup.

· Then add <FieldRefs>,this will use to show on custom based form

 <FieldRef ID="{54E2464E-94B6-4CC8-964E-C098261D022B}" Name="Title" DisplayName="EmpID" Sealed="TRUE"/>
 <FieldRef ID="{7BE8B8D4-7B6F-4042-B6FA-372578061F2A}" Name="LinkTitle" DisplayName="EmpID" Sealed="TRUE"/>
 <FieldRef ID="{8E69F964-B9A9-41A2-99AC-F25E9B8DBD07}" Name="LinkTitleNoMenu" DisplayName="EmpID" Sealed="TRUE" />

· Then include EnableContentTypes="TRUE" in the list tag

· After that add the following code to customize our windows form based content type that I have used, and in the meantime this is common to both content types

 <XmlDocuments> 
     <XmlDocument NamespaceURI ="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
         <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">                
             <Display>_layouts/ListDefUsingCTypes/FirstLCForm.aspx?mode=display</Display>  
             <Edit>_layouts/ListDefUsingCTypes/FirstLCForm.aspx?mode=edit</Edit>  
             <New>_layouts/ListDefUsingCTypes/FirstLCForm.aspx?mode=new</New>  
         </FormUrls>   
     </XmlDocument>  
 </XmlDocuments>

Add title field in the list template (if not exists)

Then find two fields LinkTitle and LinkTitleNoMenu. Then change their display name to ‘Product Code’ as shown below. These two fields are link to edit menu.

 <Field ID="{7BE8B8D4-7B6F-4042-B6FA-372578061F2A}" Name="LinkTitle" SourceID="http://schemas.microsoft.com/sharepoint/v3"
       StaticName="LinkTitle" Group="$Resources:core,Base_Columns;" ReadOnly="TRUE" Type="Computed"
       DisplayName="EmpID" DisplayNameSrcField="Title" ClassInfo="Menu" AuthoringInfo="$Resources:core,Linked_Item_With_Menu;">
         <FieldRefs>
           <FieldRef ID="{54E2464E-94B6-4CC8-964E-C098261D022B}" Name="Title" />
           <FieldRef ID="{8E69F964-B9A9-41A2-99AC-F25E9B8DBD07}" Name="LinkTitleNoMenu" />
           <FieldRef ID="{1344423c-c7f9-4134-88e4-ad842e2d723c}" Name="_EditMenuTableStart2" />
           <FieldRef ID="{2ea78cef-1bf9-4019-960a-02c41636cb47}" Name="_EditMenuTableEnd" />
         </FieldRefs>
       </Field>
       <Field ID="{8E69F964-B9A9-41A2-99AC-F25E9B8DBD07}" Name="LinkTitleNoMenu" SourceID="http://schemas.microsoft.com/sharepoint/v3"
              StaticName="LinkTitleNoMenu" Group="$Resources:core,Base_Columns;" ReadOnly="TRUE" Type="Computed"
              DisplayName="EmpID" Dir="" DisplayNameSrcField="Title" AuthoringInfo="$Resources:core,Linked_Item;">
         <FieldRefs>
           <FieldRef ID="{54E2464E-94B6-4CC8-964E-C098261D022B}" Name="Title" />
           <FieldRef ID="{9d30f126-ba48-446b-b8f9-83745f322ebe}" Name="LinkFileNameNoMenu" />
         </FieldRefs>
       </Field>

Rename the DisplayName for LinkTitle and LinkTitleNoMenu field

Modify the content in <Views> tag

Open the views tag and add the fields you want to display in default view under <View> with Default value is true as shown below.

 <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pagesviewpage.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="EmpName"></FieldRef>
           <FieldRef Name="Age"></FieldRef>
           <FieldRef Name="Address"></FieldRef>
           <FieldRef Name="Experience"></FieldRef>
           <FieldRef Name="VendorCompany"></FieldRef>
         </ViewFields>

Step 7:

Add new item in the Application page from the solution explorer with the name as FirstListForm.aspx

first_form

In the design page of the FirstlistForm.aspx , use table and scripts to design

 <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 <script type="text/JavaScript">
     function CloseDialog() {
         alert('hi ok');
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'OK clicked');
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel, 'Cancelled clicked');
     }
     function cancelDialog() {
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel, 'Cancelled clicked');
     }
     </script>    
     <table>
      <tr>
             <td>
                 EmpID
             </td>
             <td>
                 <asp:TextBox ID="txtEmpID" runat="server" MaxLength="255" />
                 <asp:RegularExpressionValidator ID="RegularExpressionValidator3" SetFocusOnError="true" runat="server" ControlToValidate="txtEmpID" ValidationExpression="^[+]?d+?$" ErrorMessage="Only Numbers"></asp:RegularExpressionValidator>
             </td>
         </tr>
         <tr>
             <td>
                 EmpName
             </td>
             <td>
                 <asp:TextBox ID="txtEmpName" runat="server" MaxLength="255" />
             </td>
         </tr>
         <tr>
             <td>
                 Age
             </td>
             <td>
                 <asp:TextBox ID="txtAge" runat="server" MaxLength="255" />
                 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" SetFocusOnError="true" runat="server" ControlToValidate="txtAge" ValidationExpression="[0-5]?[0-9]?" ErrorMessage="Only Numbers"></asp:RegularExpressionValidator>
             </td>
         </tr>
         <tr>
             <td>
                 Address
             </td>
             <td>
                 <asp:TextBox ID="txtAddress" runat="server" MaxLength="255" />
             </td>
         </tr>
          <tr>
             <td>
                 Experience
             </td>
             <td>
                 <asp:TextBox ID="txtExperience" runat="server" MaxLength="255" />
                 <asp:RegularExpressionValidator ID="RegularExpressionValidator2" SetFocusOnError="true" ControlToValidate="txtExperience" ValidationExpression="^d{0,2}(.d{1,2})?$" runat="server" ErrorMessage="Only Numbers"></asp:RegularExpressionValidator>
             </td>
         </tr>
         <tr>
             <td>
                 <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
             </td>
             <td>
                 <input type="button" value="Cancel" onclick="javascript:cancelDialog()" />
             </td>
         </tr>
     </table>
 
 </asp:Content>

Then open the FirstListForm.CS page and give the following code

 using System;
 using Microsoft.SharePoint;
 using Microsoft.SharePoint.WebControls;
 
 namespace ListDefUsingCTypes.Layouts.ListDefUsingCTypes
 {
     public partial class FirstLCForm : LayoutsPageBase
     {
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
                 LoadData();
         }
         private void LoadData()
         {
             var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
             var itemId = 0;
             if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
             {
                 int.TryParse(Request.QueryString["id"], out itemId);
             }
             if (itemId != 0)
             {
                 var listItem = list.GetItemById(itemId);
                 txtEmpName.Text = (listItem["EmpName"] == null) ? string.Empty : listItem["EmpName"].ToString();
                 txtAge.Text = (listItem["Age"] == null) ? string.Empty : listItem["Age"].ToString();
                 txtAddress.Text = (listItem["Address"] == null) ? string.Empty : listItem["Address"].ToString();
                 txtExperience.Text = (listItem["Experience"] == null) ? string.Empty : listItem["Experience"].ToString();
                 txtEmpID.Text = (listItem["Title"] == null) ? string.Empty : listItem["Title"].ToString();
             }
             if (Request.QueryString["mode"].Equals("display", StringComparison.InvariantCultureIgnoreCase))
             {
                 txtEmpName.Enabled = false;
                 txtAge.Enabled = false;
                 txtAddress.Enabled = false;
                 txtExperience.Enabled = false;
                 txtEmpID.Enabled = false;
                 btnSave.Enabled = false;
             }
         }
 
         protected void btnSave_Click(object sender, EventArgs e)
         {
             var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
             var itemId = 0;
             if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
             {
                 int.TryParse(Request.QueryString["id"], out itemId);
             }
             SPListItem listItem = null;
             if (itemId == 0)
             {
                 listItem = list.AddItem();
             }
             else
             {
                 listItem = list.GetItemById(itemId);
             }
             listItem["EmpName"] = txtEmpName.Text;
             listItem["Age"] = txtAge.Text;
             listItem["Address"] = txtAddress.Text;
             listItem["Experience"] = txtExperience.Text;
             listItem["Title"] = txtEmpID.Text;
             listItem.Update();
             Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
             Context.Response.Flush();
             Context.Response.End();
         }
     }
 }

Step 8:

Add new item in the Application page from the solution explorer with the name as SecondListForm.aspx

second_form

In the design page of the SecondListForm.aspx, use table and scripts to design

 <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 <script type="text/javascript">
     function CloseDialog() {
         alert('hi ok');
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'OK clicked');
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel, 'Cancelled clicked');
     }
     function cancelDialog() {
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel, 'Cancelled clicked');
     }
     </script>
     <table>
      <tr>
             <td>
                 EmpID
             </td>
             <td>
                 <asp:TextBox ID="txtEmpID" runat="server" MaxLength="255" />
             </td>
         </tr>
         <tr>
             <td>
                 EmpName
             </td>
             <td>
                 <asp:TextBox ID="txtEmpName" runat="server" MaxLength="255" />
             </td>
         </tr>
         <tr>
             <td>
                 Age
             </td>
             <td>
                 <asp:TextBox ID="txtAge" runat="server" MaxLength="255" />
             </td>
         </tr>
         <tr>
             <td>
                 Address
             </td>
             <td>
                 <asp:TextBox ID="txtAddress" runat="server" MaxLength="255" />
             </td>
         </tr>
          <tr>
             <td>
                 VendorCompany
             </td>
             <td>
                 <asp:TextBox ID="txtVendorCompany" runat="server" MaxLength="255" />
             </td>
         </tr>
         <tr>
             <td>
                 <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
             </td>
             <td>
                 <input type="button" value="Cancel" onclick="javascript:cancelDialog()" />
             </td>
         </tr>
     </table>
 </asp:Content>

Then open the SecondListForm.aspx.cs page and give the following code.

 using System;
 using Microsoft.SharePoint;
 using Microsoft.SharePoint.WebControls;
 
 namespace ListDefUsingCTypes.Layouts.ListDefUsingCTypes
 {
     public partial class SecondLCForm : LayoutsPageBase
     {
         protected void Page_Load(object sender, EventArgs e)
         {
             if (!IsPostBack)
                 LoadData();
         }
         private void LoadData()
         {
             var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
             var itemId = 0;
             if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
             {
                 int.TryParse(Request.QueryString["id"], out itemId);
             }
             if (itemId != 0)
             {
                 var listItem = list.GetItemById(itemId);
                 txtEmpName.Text = (listItem["EmpName"] == null) ? string.Empty : listItem["EmpName"].ToString();
                 txtAge.Text = (listItem["Age"] == null) ? string.Empty : listItem["Age"].ToString();
                 txtAddress.Text = (listItem["Address"] == null) ? string.Empty : listItem["Address"].ToString();
                 txtVendorCompany.Text = (listItem["VendorCompany"] == null) ? string.Empty : listItem["VendorCompany"].ToString();
                 txtEmpID.Text = (listItem["Title"] == null) ? string.Empty : listItem["Title"].ToString();
             }
             if (Request.QueryString["mode"].Equals("display", StringComparison.InvariantCultureIgnoreCase))
             {
                 txtEmpName.Enabled = false;
                 txtAge.Enabled = false;
                 txtAddress.Enabled = false;
                 txtVendorCompany.Enabled = false;
                 txtEmpID.Enabled = false;
                 btnSave.Enabled = false;
             }
         }
 
         protected void btnSave_Click(object sender, EventArgs e)
         {
             var list = SPContext.Current.Web.Lists[new Guid(Request.QueryString["list"])];
             var itemId = 0;
             if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
             {
                 int.TryParse(Request.QueryString["id"], out itemId);
             }
             SPListItem listItem = null;
             if (itemId == 0)
             {
                 listItem = list.AddItem();
             }
             else
             {
                 listItem = list.GetItemById(itemId);
             }
             listItem["EmpName"] = txtEmpName.Text;
             listItem["Age"] = txtAge.Text;
             listItem["Address"] = txtAddress.Text;
             listItem["VendorCompany"] = txtVendorCompany.Text;
             listItem["Title"] = txtEmpID.Text;
             listItem.Update();
             Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
             Context.Response.Flush();
             Context.Response.End();
         }
     }
 }

Step: 9

The solution explorer will look like as below

Solution_Exproler

Step 10: Right click the project in the Solution Explorer and select Rebuild then Deploy the project

Step 11:

1: Enter the URL in the IE and Run SharePoint using username and password

2: Go to Site Action -More Option- create a custom list

3: Run the Custom list

run_newitem

Then click item from new item menu and click the Permanent Employee

Permanent Emp

Then click item from new item menu and click the Contract Employee

contract_page

Step 12:

Final Result Page

Final Result

Category : SharePoint

Author Info

Gopal Muthukrishnan
 
SharePoint Developer
 
Rate this article
 
Works as SharePoint Developer in Chennai, India. ...read more
 

Leave a comment