1
votes

I am using sharpdevelop to write a program which would add items to a pre-existing list on a SharePoint website .

This is my code :

        using System.IO;
        using Microsoft.SharePoint;
        using System;


        namespace Sampl22.cs
        {
            class Program
            {
                public static void Main(string[] args)
                {
                    using (SPSite site = new SPSite("http://community.intranet/Lists/AllItems.aspx"))
                      {
                        using (SPWeb web = site.OpenWeb())                  
                             {
                                SPList list = web.Lists["Sample Forms Data"];
                                SPListItem item = list.Items.Add();
                                item["FormName"] = "New Form";
                                item["Data"] = "Description of Task";
                                 item.Update();
                             }
                      }
                }
            }
        }

and the errors that i am getting are :

The type or namespace name 'SPSite' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
The type or namespace name 'SPList' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
The type or namespace name 'SPListItem' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
The type or namespace name 'SPWeb' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

Under the references section I have:

  • FPSRVUTL
  • FPWEC
  • Microsoft.SharePoint.BusinessData.Administration.Client
  • Microsoft.SharePoint.BusinessData.Administration.Client.Intl
  • System
  • System.Core
  • System.Data
  • System.Data.DataSetExtensions
  • System.Xml
  • System.Xml.Linq

What should be done in order to remove these errors ?

2

2 Answers

2
votes

SPSite lives in Microsoft.SharePoint (Microsoft.SharePoint.dll). All of the failures beyond that are part of the cascade of a missing reference. You should also check which .NET Framework you're running. Most development is done under 4.0 at the moment (not client profile)

2
votes

As Graham said you need to add the assembly Microsoft.SharePoint.dll into your references in order to use it. You can find this DLL on the SharePoint server that you're working with:

On SharePoint 2013 it lives at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI

And on SharePoint 2010 it can be found at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI