RSS

Tag Archives: Code Snippets

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.

CODE SNIPPET

{

            try
            {

               
                //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;

                oListItem.Update();             
                            
             
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }

View the UPDATED CODE HERE

Advertisements
 
16 Comments

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: , ,

How to show Outlook INBOX & TASK in sharepoint sites?


Add a Content Editor Webpart  (CEWP) to page and paste the below code.

Inbox

<OBJECT classid=”CLSID:0006F063-0000-0000-C000-000000000046″

 width=”100%”>

  <param name=”Folder” value=”Inbox”>

</OBJECT>

 

Tasks

<OBJECT classid=”CLSID:0006F063-0000-0000-C000-000000000046″

 width=”100%”>

  <param name=”Folder” value=”Tasks”>

</OBJECT>

This is not a perfect solution for showing inbox in portal but a quick and simple tip….Enjoy!

Voila!

 
Leave a comment

Posted by on March 22, 2009 in Code Snippets, Tips & Tricks, Webpart

 

Tags: , , ,