Category Archives: ASP.NET

Programmatically insert an item in sharepoint list using ASP.NET user control

  • Create a new web project in Visual studio
  • Add reference to Microsoft.SharePoint.dll  (you can find from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI)
  • Create an new user control(.ascx)
  • Import below namespaces
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Search;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;
  • Insert Textboxes, buttons….whatever u required
  • On button click paste the code below
  • To host the user control in sharepoint use smartpart from codeplex.




                //create the object of SPSite
             SPSite oSiteCollection = SPContext.Current.Site;

           // SPSite oSiteCollection = new SPSite(“http://mysite:3434“);

                //create the object of SPWeb with the help of SPSite object:
                SPWeb oWebsiteRoot = oSiteCollection.OpenWeb();
                oWebsiteRoot.AllowUnsafeUpdates = true;

                //create the connection to the custom List and create object of SPListItemCollection
                SPList oList = oWebsiteRoot.Lists[“MyListName”];
                SPListItemCollection listItemCOll;

                //add the item in the User List
                SPListItem oListItem = oList.Items.Add();
                oListItem[“Name”] = txtName.Text;
                oListItem[“Email”] = txtEmail.Text;
                oListItem[“Color”] = ddldropdown.SelectedItem;
                oListItem[“AssignTo”] = txtAssignto.Text;

            catch (Exception ex)
                lblError.Text = ex.Message.ToString();



Posted by on April 21, 2010 in ASP.NET, Code Snippets


Tags: ,

Code Snippet: How to get client machine name?

I had a requirement to get client’s machine name   using smartpart user control in sharepoint . i have tried number of methods but unfortunately those show server name only.

here  is the code which works fine.

Dim host As  System.Net.IPHostEntry

host = System.Net.Dns.GetHostEntry(Request.ServerVariables.Item(“REMOTE_HOST”)) 

Dim strComputerName As String = host.HostName

label1.text= strComputerName

1 Comment

Posted by on April 15, 2009 in ASP.NET, Code Snippets, Tips & Tricks


Tags: , ,

ASP.NET MVC 1.0 released

ASP.NET MVC is a free, fully supported, Microsoft product that enables developers to easily build web applications using a model-view-controller pattern.  ASP.NET MVC provides a “closer to the metal” web programming option for ASP.NET.  It enables full control over HTML markup and URL structure, and facilitates unit testing and a test driven development workflow…..(text soure:

to know more about ASP.NET MVC, have a look at Scott Gu’s blog here….

Here is an amazing must see video by Scott Hanselman (No slides. Just code. Start with File|New and build a real Web site with ASP.NET, ASP.NET AJAX, Authentication, Authorization, MVC, Microsoft SQL Server and jQuery in sixty-five minutes or less)

 Creating with Microsoft ASP.NET Model View Controller (MVC)

ASP.NET MVC Overview

Leave a comment

Posted by on April 7, 2009 in ASP.NET, New Releases, Video