Skip to main content

TechBlog

Go Search
About
TechBlog
SharePoint Development
  

Blue Surf Tech > TechBlog
SharePoint and other ramblings
Adding a Sharepoint  list item using the Sharepoint web service Lists.asmx

The built in Sharepoint webservices are a great way to add list items programatically.  Here’s a code sample to get you started.  This is a simple Windows application with a form that submits values into a Sharepoint 2007 list.

 

To get started, create a Windows application in Visual Studio 2008.  Add a web reference to your Sharepoint list’s web service. 

 

How to add the web reference:

Right click the "References" folder in the Solutions explorer.  Add a "Services" reference.  Find and click the "Advanced" button on the lower left.  Click "Add web reference" on the lower left.  Enter your Lists.asmx url.

 

 Add a few text boxes and a button to your windows form.   The form will take the 2 values, “Title,” and “Message,” and add them to the Sharepoint list.  I created 3 text boxes on my form.  txtTitle, txt Message, and txtStatus.  The first 2 are mapped the the Title and Message fields on my Sharepoint list.

 

  

 

 

 Make sure you do the following:

 

1.        When adding your web service reference, make sure you add it at the site level where your list is located.  For  example http://SPServer/SubSite1/_vti_bin/Lists.asmx if your list is located in SubSite1.  The web service at the root will appear to work, but you will get an error saying “The list that is referenced here no longer exists.”

 

2.       Make sure you check the app.config.  There’s a bug in Visual Studio in case you delete and re-add your web service reference that retains the first one you added.

 

 

3.       Use either the GUID or the List name to access your list.  The GUID can be found in the URL when you edit the list settings.  Hint: Translate the the url-encoded symbols.  The first and the last are brackets, the middle ones are dashes

a.       %7b = {

b.      %7d = }

c.       %2D = -

 

 

Here’s the code to add the item to the list.  Basically, you are sending in an xml batch to the webservice with the command and the values to insert.

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Xml;

 

 

namespace TestListsWebservice

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void btnSubmit_Click(object sender, EventArgs e)

        {

            AddListItem();

        }

 

        private void AddListItem()

        {

 

            string strBatch = "<Method ID='1' Cmd='New'>" +

                "<Field Name='Title'>" + txtTitle.Text + "</Field>" +

                "<Field Name='Message'>" + txtMessage.Text + "</Field></Method>";

 

 

            ListsWS.Lists listService = new ListsWS.Lists();

 

            // SharePoint Web Serices require authentication

            listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

 

          

            //Either GUID or list name will work.

            // String listName = "{209B7C81-6313-4A5D-B0A2-4EB5A58B8538}";

             String listName = "MyListName";

 

            XmlDocument xmlDoc = new System.Xml.XmlDocument();

            System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

            elBatch.SetAttribute("OnError", "Continue");

            elBatch.SetAttribute("ListVersion", "1");

 

            elBatch.InnerXml = strBatch;

           

            XmlNode ndReturn = listService.UpdateListItems(listName, elBatch);

 

            txtStatus.Text = ndReturn.OuterXml.ToString();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

        }//

    }

}

 

Sharepoint Reporting Services Integrated Mode - How to find all the reports that use a datasource (rsds)

Sharepoint Reporting Services Integrated Mode - How to find all the reports that use a datasource (rsds)

So here's a nice little problem. Running SSRS in Sharepoint Integrated mode is nice. Nice reports, easy interface, easy permission administration. Nice metadata on reports for filtering, etc.

So, now you have to change a data source. Well, how do you know which of your hundreds of reports are pointing that RSDS file?

After digging and digging through GUID's in the Sharepoint tables (a great way to spend the afternoon), I finally found where the data sources join with the RDL files. It's actually in 2 different databases. There is an item in the ReportServer database in the Datasource table which lists all data sources.  The ItemID in that table is actually the GUID for the RDL file which is stored in the AllDocs table in the content database.   

So, in the spirit of sharing, here's a few lines of code that will save someone many hours of digging through GUIDS...

 

 

select report.leafname, rdl.leafname from RSSharePoint.dbo.DataSource ds

inner join WSS_Content_MyName.dbo.AllDocs report

on ds.ItemID = report.ID

inner join WSS_Content_MyName.dbo.AllDocs rdl

on ds.Link = rdl.ID

 

Installing MOSS 2007 on Server 2008 using NLB
John Lee from Microsoft has a nice post on installing MOSS 2007 using a Server 2008 load balanced farm.  He walks you through installing a load-balanced 2 server front end, with a separate Index server and SQL server, as well as Kerberos authentication.
 
 
 
 
 
1 - 3 Next

 ‭(Hidden)‬ Admin Links

Adding a Sharepoint list item using the Sharepoint web service Lists.asmxUse SHIFT+ENTER to open the menu (new window).
Sharepoint Reporting Services Integrated Mode - How to find all the reports that use a datasource (rsds)Use SHIFT+ENTER to open the menu (new window).
Installing MOSS 2007 on Server 2008 using NLBUse SHIFT+ENTER to open the menu (new window).
The Sharepoint way for Application Error AlertsUse SHIFT+ENTER to open the menu (new window).
Setting Workflow Configuration Settings Dynamically From a List (updated with code)Use SHIFT+ENTER to open the menu (new window).
Another SharePoint Reminder TicklerUse SHIFT+ENTER to open the menu (new window).
SharePoint workflow in Visual Studio 2008 Error: Failed on StartUse SHIFT+ENTER to open the menu (new window).
Building a home VM server farm on a Dell Inspiron 530Use SHIFT+ENTER to open the menu (new window).
Cool SharePoint PostersUse SHIFT+ENTER to open the menu (new window).
Contacts Management Template foolishnessUse SHIFT+ENTER to open the menu (new window).
SharePoint 2007 backup softwareUse SHIFT+ENTER to open the menu (new window).
Reporting Services SharePoint Integration mode Installation GotchaUse SHIFT+ENTER to open the menu (new window).
SSRS Installation for SharePointUse SHIFT+ENTER to open the menu (new window).
All 40 SharePoint templates with screenshots Part 4Use SHIFT+ENTER to open the menu (new window).
All 40 SharePoint templates with screenshots Part 3Use SHIFT+ENTER to open the menu (new window).
All 40 SharePoint templates with screenshots Part 2Use SHIFT+ENTER to open the menu (new window).
All 40 SharePoint templates with screenshots Part 1Use SHIFT+ENTER to open the menu (new window).
40 SharePoint 2007 TemplatesUse SHIFT+ENTER to open the menu (new window).
SharePoint Migration ToolUse SHIFT+ENTER to open the menu (new window).
Moving to 64 bitUse SHIFT+ENTER to open the menu (new window).
MOSS custom workflow deploy errorUse SHIFT+ENTER to open the menu (new window).
MOSS Workflow deploy error: Shows up but InactiveUse SHIFT+ENTER to open the menu (new window).
Workflow deploy error: Farm is unavailableUse SHIFT+ENTER to open the menu (new window).
SharePoint Designer Reminder System (Tickler workflow)Use SHIFT+ENTER to open the menu (new window).
Sharepoint workflow wf hot fix 4/2007Use SHIFT+ENTER to open the menu (new window).
Regular Expression ToolUse SHIFT+ENTER to open the menu (new window).
SharePoint Planning and Architecture Parts 1 and 2Use SHIFT+ENTER to open the menu (new window).
Using Log Parser to parse media server and flash filesUse SHIFT+ENTER to open the menu (new window).
MS Blog on using the Record Center template in Sharepoint 2007Use SHIFT+ENTER to open the menu (new window).
quicktime streamingUse SHIFT+ENTER to open the menu (new window).
TechNet for Sharepoint Workflow 2007Use SHIFT+ENTER to open the menu (new window).
Walkthrough MOSS 2007 install with screenshotsUse SHIFT+ENTER to open the menu (new window).
How to stream a quicktime movie from a web pageUse SHIFT+ENTER to open the menu (new window).
What's the difference betwee Sharepoint 2007 MOSS and WSS?Use SHIFT+ENTER to open the menu (new window).
Excel Services Step By StepUse SHIFT+ENTER to open the menu (new window).
Sharpoint Team BlogUse SHIFT+ENTER to open the menu (new window).
SQL Server Reporting 2005 ChartsUse SHIFT+ENTER to open the menu (new window).
New Biztalk help filesUse SHIFT+ENTER to open the menu (new window).
Virtual serversUse SHIFT+ENTER to open the menu (new window).
Basic Biztalk direct bindUse SHIFT+ENTER to open the menu (new window).