DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Posts Tagged ‘ASP.NET’

Custom Silverlight Navigation with the SP PortalSiteMapProvider

Posted by PANVEGA on June 2, 2009

In this post I wanna explain in a few steps how to develope a custom Silverlight Navitgation for SharePoint publishing sites (Source Silverlight Blueprints on CodePlex)

SharePoint and Silverlight Blueprints on CodePlex were uploaded to include two more Silverlight RTM samples: custom navigation in SharePoint and the colleague viewer. These blueprints provide samples for you to build and explore using Silverlight as an alternate way to develop and integrate powerful user experiences within SharePoint and add rich Internet application functionality to your SharePoint sites. Included in the overall set of samples are a Hello World sample, a Slider sample, and the recently added Custom Navigation and Colleague Viewer samples added

Read the rest of this entry »


Posted in ASP.NET, C#, DotNet, MasterPage, MOSS, Silverlight | Tagged: , , , , , | 1 Comment »

Dual Authentication Providers in SharePoint 2007

Posted by PANVEGA on March 17, 2009

In a production environment, I would opt to install both on to a machine even though it will be primarily Internet\Extranet facing, even if it is using the local directory services.  This gives a backdoor to managing the site should you have problems with the forms authentication mechanism (or other).

In order having many different third party authenticatin providers for your SP application you can solve this problem in SharePoint 2007. In the new version different authentication providers are supported. In fact, different providers can be used together for the same site! A major improvement which will make a lot of people very happy.

A single web application only supports a single authentication provider, such as Windows, Forms, etc. That mean, you can not use one application (Domain namsepace) for 2 or more authentication providers. Read the rest of this entry »

Posted in Administration, ASP.NET, IIS, Infrastructure, MOSS, Security, SQL | Tagged: , , , , , | 2 Comments »

MasterPage/PageLayout format DateTimeField

Posted by PANVEGA on March 16, 2009

When you are creating a SharePoint MasterPage or a Page Layout and you what to have a specific datetime format like dd.MM.yyyy  it’s not possible using just the publishing date field of SharePoint. However you can also create a new aspx page with a cs codebehind class and formating the date field, but it is much more offer to achieve this goal (developement, deployment etc.). See the following links below.

Current Situation:

I created a PageLayout with a Custom Content Type DateTime called MyDate field. The field is shown only with this format dd\MM\yyyy. I needed this format dd.MM.yy. Out of the box, you cannot format the date field.  The default date asp code behind look like this:

<SharePointWebControls:DateTimeField FieldName=”MyDate” runat=”server” id=”DateTimeField2″ CssClass=”datetimefield” >
</SharePointWebControls:DateTimeField> Read the rest of this entry »

Posted in Field Types, MasterPage, MOSS | Tagged: , , , | Leave a Comment »

Using ASP in JavaScript for URL Encoding in SharePoint fields

Posted by PANVEGA on February 3, 2009

In this post I want to show you how to rebuild the standard MyLinks –> Add to My Links for a custom MyLinks Control in Visual Studio and using ASP in JavaScript.

Active Server Pages exposes an object called ServerVariables, which is part of the Request object. This ServerVariables object allows the programmer to see many environment variables. You can use the ServerVariables along with IIS’s directory sercurity options to determine who is currently accessing your site. You can also grab the visitor’s IP address using the ServerVariables object. This article includes a question and answer from the Activer Server Pages mailing list, as well as an excerpt from the Visual InterDev 1.0 help files detailing all of the properties of the ServerVariables object. (4. How to develop your custom MyLink Control in Visual Studio.) Read the rest of this entry »

Posted in ASP.NET, C#, Delegate Controls, Deployment, DotNet, JavaScript, MOSS, My Links, My Site | Tagged: , , , , , , , | 2 Comments »

SharePoint Exception Handling and Logging

Posted by PANVEGA on January 21, 2009

Error and exception handling is very important in creating a robust and high quality system and more importantly for trouble shooting. Error and exception handling must be done correctly so that potential issues with the system can be diagnosed quickly.

The Basics

  • Always display a high level abstract message to the user when an error occurs or an exception is thrown rather than a low level exception message that the user will not understand. The low level specific error message should be written to the log file.
  • Check objects, values, properties etc before using them so that unexpected exceptions are not thrown.  For example
    • When obtaining an object always check the object is not null before using it.
    • Always check strings to make sure they are not empty or null i.e. String.IsNullOrEmpty(“aString”)
  • Never use try catch blocks to control the logic of your code, it is more efficient to use if/else statements and only throw exceptions when nothing else can be done.
  • When casting always check the object can be cast to the particular object. For example:

if(MyObject is String)


// Cast object your object

} Read the rest of this entry »

Posted in ASP.NET, C#, Deployment, DotNet, MOSS | Tagged: , , , | Leave a Comment »

Integrate an UserControl .ascx into a .aspx Page

Posted by PANVEGA on July 4, 2008


User controls provide a means by which custom graphical interfaces can be created and reused. A user control is essentially a component with a visual representation. As such, it might consist of one or more Windows Forms controls, components, or blocks of code that can extend functionality by validating user input, modifying display properties, or performing other tasks required by the author. Read the rest of this entry »

Posted in ASP.NET, DotNet, UserControls | Tagged: , , , | Leave a Comment »

Customize the SharePoint Navigation Quick Launch

Posted by PANVEGA on April 18, 2008

You can modify the display of Quick Launch Naviagtion in SharePoint by modifying attributes of the navigation control specified in the default.master file. You can display a collapsed view with fly-out menus by creating a custom .master file or using the SharePoint object model. You can also create a custom .master file and use the Windows SharePoint Services object model to point a site to the new file.

The default.master file is the Windows SharePoint Services master page that contains templates for site page layout, including the template for the left navigational area used in SharePoint pages.

You find the master pages under your server /_calatlogs/masterpage or Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL. You can use e.g. the SP Designer to edit remotely your master page on your IIS. There you find the tag SharePoint:AspMenu and PublishingNavigation:PortalSiteMapDataSource with some usefull attributes to customize the Navigation as you wishes. YOu have to try a little bit to get a feeling how to combine diferent attributes together.

<asp:AspMenu id=”QuickLaunchMenu” DataSourceId=”QuickLaunchSiteMap” runat=”server” Orientation=”Vertical” StaticDisplayLevels=”1″ ItemWrap=”true” MaximumDynamicDisplayLevels=”1″ StaticSubMenuIndent=”0″ SkipLinkText=””>

DataSourceID Specifies the data source control that provides the hierarchical data for this menu. In the previous example code, the DataSourceID points to a control with the ID “GlobalNavDataSource”.
Orientation Specifies whether the menu is horizontal or vertical. In the previous example code, the orientation is horizontal.
StaticDisplayLevels Specifies the number of hierarchy levels to show in the menu at the same time.In this example, “1” is specified, indicating that the menu displays one level of hierarchy below the top-level site.
MaximumDynamicDisplayLevels Specifies the number of levels to show in dynamic fly-out menus.In this example, “1” is specified, indicating that the menu item on the first level of the site hierarchy with child sites or pages displays those sites or pages in fly-out menus.

<PublishingNavigation:PortalSiteMapDataSource ID=”SiteMapDS” Runat=”server” SiteMapProvider=”CurrentNavSiteMapProvider” EnableViewState=”true” StartFromCurrentNode=”true” StartingNodeOffset=”0″ ShowStartingNode=”false” TrimNonCurrentTypes=”Heading”/>

ShowStartingNode Affects whether the starting node is returned by the data source.When this property is set to true, the data source returns the starting node. The menu receives the starting node, which can be the root node, and items below the starting node.

When this property is set to false, the data source does not return the starting node. The menu receives only the items below the starting node.

StartFromCurrentNode Affects where the data source starts. That is, this property sets which section of the overall site hierarchy the data source control returns to the menu.When this property is set to true, Office SharePoint Server 2007 instructs the PortalSiteMapDataSource object to apply its rules for determining where it should be starting.
StartingNodeOffset Gets or sets a positive or negative integer offset from the starting node that determines the top-level site hierarchy that is exposed by the DataSourceControl object.The default is 0, which indicates that the top-level site hierarchy exposed by the SiteMapDataSource object is the same as the starting node.

The effect of this property is variable, undefined, and depends on site hierarchy details that are out of scope for this topic.

TrimNonCurrentTypes Allows context-based and type-based node trimming.In this example, TrimNonCurrentTypes=”Heading”, which instructs the data source to remove any nodes of type Heading that are not directly below the current node.

You can specify multiple values for this property in a comma-delimited list. Available values are defined in the NodeTypes enumeration.

TrimNonAncestorTypes Trims any specified types that are not directly below the current site or one of its ancestors.
TrimNonAncestorDescendantTypes Trims any nodes of specified types that are not below the current site or one of its ancestor or descendant sites.
TreatStartingNodeAsCurrent Affects which node is treated as the current node for trimming purposes. By default, current node refers to the node representing the item that is currently being visited.When TreatStartingNodeAsCurrent is set to true, the starting node of the data source is treated as the context or trimming node.


First open the default.master file in an editor and search for “MaximumDynamicDisplayLevels”. Once you find the MaximumDynamicDisplayLevels property of the <SharePoint:AspMenu> element change the number to the requested number of levels. For example to get 3 sub menu item levels to be displayed in the Top Navigation Bar simply change the number to 3.


Once you’ve made the change save and close the file. After saving your changes you should refresh your page and see that more levels are displayed on your SharePoint Top Navigation Bar. The below image shows the Top Navigation Bar when the MaximumDynamicDisplayLevels is set to 3.

You can display multiple menu levels in the static menu by setting the StaticDisplayLevels property to a value greater than 1. You can also display additional levels in dynamic menus by setting this property to a value greater than 0. For example, if you display two menu levels in the static menu (by setting the StaticDisplayLevels property to 2) and then set this property to 3, three additional menu levels are displayed in dynamic menus. All remaining higher menu levels (if any) are discarded.

Setting this property to 0 displays a flat menu up to the level specified by the StaticDisplayLevels property, without any dynamic menus.

To control dynamic display behavior, use this property to specify how many additional menu levels should dynamically appear after the static display level. For example, if the menu has a static level of 3 and a max dynamic level of 2, the first three levels of the menu would be statically displayed, while the next two levels would show dynamically.

The following example demonstrates how to use the MaximumDynamicDisplayLevels property to limit the number of menu levels to display in a dynamic menu.

<asp:menu id = “navigationMenu” staticdisplaylevels=2 staticsubmenuindent=10 orientation = “Vertical” maximumdynamicdisplaylevels=3 target = “_blank” runat = “server”></asp:menu>

More Sources:

Posted in ASP.NET, MasterPage, MOSS | Tagged: , , | 8 Comments »

Custom SharePoint People Picker

Posted by PANVEGA on February 22, 2008

In this example I wanna show you how to customize the SharePoint people picker in a custom webpart with some additional controls.

SharePoint provides a control known as a “people picker” that allows users to search for and select users defined at some specified scope. This control is normally associated with Personnel field in a SharePoint List.

The control is actually called a “PeopleEditor” and is in the ‘Microsoft.SharePoint.WebControls‘ namespace. You will need to add a reference to ‘Microsoft.Sharepoint.dll’ to your project in Visual Studio, which is something you probably already have if you are writing anything that works with SharePoint.

Here’s a list of the people picker properties that can be set ()



The People Picker can only do wildcard searches for AD Windows group names. With any role provider other than the out of the box AD one the role provider lookup is specific to the entire name. For example if you have a group called “Readers” and you enter “Read” in the People Picker search dialog, it will not find your group; if you enter “Readers” it will. The role provider doesn’t provide a good way to do wildcard group search. See “Multiple Auth Providers” for more info. As well Steven Fowler in figuring out a custom membership provider has some great insights, another post People Picker and Custom Membership provider has dev insights on the GetUser() method.

The code creates three controls – a PeopleEditor (from the Microsoft.SharePoint.WebControls namespace), a button and a textbox. The button has an click event that itirates over the users picked in the PeopleEditor and writes them to the text box for instance with a stringbuilder. However you can add any control you are looking for.

First, create a custom webpart in visual studio. Read my post first develope-a-custom-webpart-in-moss.

Read the rest of this entry »

Posted in DotNet, MOSS, WebParts | Tagged: , , , | 2 Comments »

different appendages for a custom aspx page to SharePoint

Posted by PANVEGA on February 7, 2008

In this post I am going to show how to add a custom aspx page to SharePoint. Maybe you already have developed an ASP .Net Web Application with many web forms, user controls, business layer, and data access layer and want to add this aspx page to SharePoint. In this post I´m going to explain some different ways how to integrate an aspy page.

The goal is to integrate the files within this web application into the SharePoint site and totally get rid of the web application. This has couple of advantages:

  1. Business users and end users need not go to a separate web application (URL). Users can see all those pages within SharePoint site.
  2. Once the integration is done, we have the SharePoint site’s security and access rules i.e. Authentication and Authorization is in place without any additional work.
  3. Simple development experience as compared to developing with web parts.

Read the rest of this entry »

Posted in ASP.NET, Deployment, Infrastructure, MOSS | Tagged: , , , | Leave a Comment »

Attachements to a list item using SharePoint Webservices

Posted by PANVEGA on December 16, 2007

In this short post I wanna describe how to add files as an Attachment to a SharePoint list item.

In my previous post Consuming lists.aspx Webservice from SharePoint I showed you how to manage a SharePoint List Webservice. Now I´m gonna add a little bit more tricky thing to the custom cosuming WS method.

Adding an Attachment you need the Add Attchment(..) Method in the lists.asmx Webservice.

public string AddAttachment (
    string listName,
    string listItemID,
    string fileName,
    byte[] attachment


A string that contains either the title or the GUID for the list.
A string that contains the ID of the item to which attachments are added. This value does not correspond to the index of the item within the collection of list items.
A string that contains the name of the file to add as an attachment.
A byte array that contains the file to attach by using base-64 encoding.

Return Value

A string that contains the URL for the attachment, which can subsequently be used to reference the attachment.

Here is an example where I developed a custom ASP.Net Webservice which consumes the Sharepoint lists.aspx Webservice:

[WebMethod(Description = “Set the job appliaction object”)]
public string setApplication(Applicant applicant, string comment, string attache_name, byte[] content)

//here follows the CAML XMLElement method, see my previous post for detailed information


XmlNode return_node = setservice.UpdateListItems(listname, element);

if (return_node.InnerText == “0×00000000″)

if (attache_name != null && content != null)
string return_value = setservice.AddAttachment(listname, return_node.SelectSingleNode(“//@ows_ID”).Value, attache_name, content);



the setApplication(..) function receives an object with all necessary attributes for a job applicant from a ASP.Net Website formular. After adding the job application object successfully to the custom list, go ahead and check the return message. In the return_node you fin the following XML structure:

<Results xmlns="">
   <Result ID="1,Update">
      <z:row ows_ID="4" ows_Title="Title" ows_Modified="2003-06-19 20:31:21"
         ows_Created="2003-06-18 10:15:58" ows_Author="3;#User1_Display_Name"
         ows_Editor="7;#User2_Display_Name" ows_owshiddenversion="3" ows_Attachments="-1"
         ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title"
         ows_SelectTitle="4" ows_Order="400.000000000000"
         ows_DateColumn="2003-09-04 00:00:00" ows_NumberColumn="791.00000000000000"
         xmlns:z="#RowsetSchema" />

Check the response ErrorCode message. If you receive this 0x00000000 everything was without any errors.

In the next step choose the setservice.AddAttachment(listname, return_node.SelectSingleNode(“//@ows_ID”).Value, attache_name, content); Method. You need the name or GUID from your SharePointlist.

Now comes the tricky thing, in the return node you see the ows_id attribute with the ID =4. This is the new Item ID you created in the previous step. The ID is important to identify the appopriate item in the list.

Using XPATH to catch the item id from the return node. Then you only need the name and the byte code of the file. Thats all you need to add a file to a Sharepoint item.

ASP.NET Web formular example:

Read the rest of this entry »

Posted in ASP.NET, C#, MOSS, WebServices, XML, XPath | Tagged: , , , , , , , | 2 Comments »

How to Add Actions to the User Interface?

Posted by PANVEGA on October 10, 2007

This example shows how to add custom actions to various menus in SharePoint through a Feature.

  1. Create a UserInterfaceCustomActions folder within the setup directory at the following location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.
  2. Create your custom feature.xml file in visual studio
  3. Create a elements.xml file with for example some CustomActions. Define here elements for the various actions included within the feature. For the sake of example, the URL for each action points to an .aspx file and passes it a value that identifies the source of the request. <UrlAction Url=”/_layouts/CustomHello.aspx?ViewToolbar”/>
  4. Create a aspx with custom example code CustomHello.aspx with some URL Parameters Queries and some text when the users clicks on the Hypetlink in the CustomAction string clientQuery = Page.Request.QueryString[“ListId”];
  5. Copy the file into the Layouts in the 12 MOSS Directory. Better using your Solution.
  6. Create also a UserControl file with some simple input CustomHello.ascx
  7. Copy the file into the ControlTemplates in the 12 MOSS Directory
  8. At a command prompt to install the Feature in the deployment, activate the Feature on a specified subsite
  9. Then reset Microsoft Internet Information Services (IIS) so that the changes can take effect.
  10. To see the various custom actions that you have added, navigate to the following locations from the home page of a Web site in the site collection:
  • Click Site Actions to see the new action on the Site Actions menu.
  • Click Site Settings on the Site Actions menu to see a new action in the Look and Feel section of the Site Settings page.
  • Navigate to a document library and open each menu on the toolbar to see a new action on each menu.
  • In a document library that contains items, click the down arrow for an item to see the new action on the edit control block menu.
  • On the edit control block menu for an item, click View Properties and Edit Properties to see new actions on the Display form and Edit form toolbars.

here you find some Default Actions:


<Elements xmlns=””&gt;
<!– 1. Document Library Toolbar New Menu Dropdown –>
<CustomAction Id=”UserInterfaceLightUp.DocLibNewToolbar”
<UrlAction Url=”/_layouts/LightupHello.aspx?NewMenu”/>

<!– 2. Document Library View Toolbar Main Link –>
<CustomAction Id=”UserInterfaceLightUp.DocViewToolbarStatic”
<UrlAction Url=”/_layouts/CustomHello.aspx?ViewToolbar”/>

<!– 3. Document Library Toolbar View Toolbar Main Control –>
<CustomAction Id=”UserInterfaceLightUp.DocViewToolbarDynamic”

Read the rest of this entry »

Posted in ASP.NET, Deployment, MOSS, UserControls | Tagged: , , , , | 1 Comment »

Consuming Lists.asmx Webservice from SharePoint

Posted by PANVEGA on September 15, 2007

In this post I wanna shortly describe how to hanlde with SharePoint Webservice in this case I´m gonna show an examole with the lists.asmx Webservice. SharePoint (WSS 2.0) provides several web services that gives you access to different parts of the object model and its data, without the need to use the object model directly and without worrying where the data is stored in a farm deployment.

The Lists Web service provides methods for working with SharePoint lists, content types, list items, and files. To access this Web service set a Web reference to http://<site>/_vti_bin/Lists.asmx.


An important detail when programming against the SharePoint web services is to remember to set the .Url property of your web reference to point to the correct WSS team site. The lists.asmx web service is a virtual service and is by SharePoint magic available in all WSS sites, not only in the IIS virtual directory /_vti_bin/. In addition, remember to apply correct credentials for authentication.

Set the .Url like this http://<site>/_vti_bin/Lists.asmx. (avoid getting //_vti_bin/).

So why would we want to use the SharePoint webservice? All site page data and document data is stored in SQL server and compiled into SharePoint pages/documents upon request. It is not recommended that you tamper with the data directly in SQL server as it’s very easy to break a WSS site altogether very easily. That leaves 2 methods of accessing data from a SharePoint database, the SharePoint object model, or webservice.

A full list of webservice methods for things such as alerts and sites are available in the SharePoint Products and Technologies 2003 SDK. I’ll hopefully cover them all in time, but today we’ll focus on just the list webservice.

Here are the methods and their definitions as taken from the SDK:

AddAttachment – Adds an attachment to the specified list item in the specified list.
AddList – Creates a list in the current site based on the specified name, description, and list template ID.
DeleteAttachment – Removes the attachment from the specified list item.
DeleteList – Deletes the specified list.
GetAttachmentCollection – Returns a list of the URLs for attachments to the specified item.
GetList – Returns a schema for the specified list.
GetListAndView – Returns the list and view schemas for the specified list.
GetListCollection – Returns the names and GUIDs for all the lists in the site.
GetListItemChanges – Returns changes made to the list since the specified date and time.
GetListItems – Returns information about items in the list based on the specified query.
UpdateList – Updates a list based on the specified field definitions and list properties.
UpdateListItems – Adds, deletes, or updates the specified items in a list on the current site.

So lets get using this webservice. It’s worth reminding you that I’m using Visual Studio.Net 2003 for this (not VS 2005!). You can add a SharePoint webservice exactly the same way you’d add any other webservice, just right click on the references folder and then ‘Add Web Reference…”. Plant the url to sites webservice you wish to call in the next box, give it a decent name and click ok.

The first webservice method we’ll use is GetList. We can pass in the name of the list as a string as a parameter and it returns an XmlNode with the schema represented in the InnerXml value of the node. The most important piece of information you’ll get is the list guid as you’ll need this do use some of the various other list webservice methods. Here’s our first bit of code:

Site1.Lists listsWS = new SharePointWebservice1.Site1.Lists();
listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode list = listsWS.GetList(“Contacts”)

Once it’s completed go back to your contacts list on the SharePoint site and you’ll see a field for filling in the ‘Last Contacted’ date for all your contacts.


When the UseDefaultCredentials property on an instance of a client proxy class is set to true the client will use the default credentials to authenticate to the Web service. The Web service in this sample must be configured to support integrated Windows authentication in the IIS Configuration Permission to properly demonstrate passing default credentials.

The CredentialCache is used to store system credentials for Internet-based resources. By default, when the System.NET.Credential Cache.GetCredentials method is called this compares the URI authentication type provided with any stored in the cache and returns the first set of matching credentials. The DefaultCredentials property is used to represent the system credentials for the current security context in which the application is running. For client-side applications, these are typically the current users’ Windows credentials.

However, within ASP.NET applications these default credentials are either the logged-in user, or the current user being impersonated. It is also important to remember that this property only applies to NTLM, negotiate, and Kerberos based authentication.

Site1.Lists listsWS = new SharePointWebservice1.Site1.Lists();
listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode list = listsWS.GetList(“Contacts”);

XmlDocument doc = new XmlDocument();
XmlNode ndProperties = doc.CreateNode(XmlNode.Element, “List”, “”);
XmlAttribute ndTitleAttrib = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, “Title”, “”);
XmlAttribute ndDescription = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, “Description”, “”);
XmlNode ndNewFields = doc.CreateNode(XmlNodeType.Element, “Fields”, “”);

string listName = list.Attributes[”ID”].Value;
string listVersion = list.Attributes[”Version”].Value;

ndTitleAttrib.Value = “Contacts”;
ndDescription.Value = “My contacts list”;


ndNewFields.InnerXml = “<Method ID=’1′><Field Type=’DateTime’ DateOnly=’TRUE’ Required=’TRUE’
DisplayName=’Last Contacted’ FromBaseType=’TRUE’/></Method>

listsWS.UpdateList(listName, ndProperties, ndNewFields, null, null, listVersion);

The two null values that are passed in are for updateFields and deleteFields. Again for these two fields you need to pass in CAML pretty much the same way as you did for adding fields. Check the SharePoint SDK for values you can pass in to accomplish updates and deletes.

This namespace implements the server-side interface for calling SharePoint-based XML Web services. It contains classes that implement the Windows SharePoint Services Web service and Web services for working with Web Part Pages and Web Parts. In addition, most of the methods within the defined classes are not designed to be called directly from the server but remotely from client applications. The Simple Object Access Protocol (SOAP) interfaces used in these services provide .NET developers with object models that are used to create solutions that work with both WSS and SPS.

Parameters for the CAML Method for updateListItems()

listName A string that contains the internal name of the list.

updates A Batch element that contains one or more methods for updating items and that can be assigned to a System.Xml.XmlNode object, as in the following example.

The ID attribute in each Method element uniquely identifies the specific update so that errors and return values can be properly identified. Each method that is posted contains Field elements that specify the ID of the item and the new field value for the item. The field ID does not correspond to the index of the item in the collection of items for the list.

For descriptions of the various formats used for field types that can be passed in this parameter see SPListItem.

One that could actually be useful, is to be able to actually add new list items to our list using the lists webservice. The method we call for inserting items is the same method used to ammend and delete list items. The Guid of the list is passed in as the first parameter, with the second being an XmlNode. The basics of being able to perform operations on list items is done using CAML again. Below is the code and CAML that I’m going to be running to insert a new item into a custom lists:

returnService = new VIEMossService.Lists();
//returnService.Credentials = System.Net.CredentialCache.DefaultCredentials;
string user = System.Configuration.ConfigurationSettings.AppSettings[“User”];
string password = System.Configuration.ConfigurationSettings.AppSettings[“Password”];
string domain = System.Configuration.ConfigurationSettings.AppSettings[“Domain”];
returnService.Credentials = new NetworkCredential(user, password, domain);
string serviceUrl = System.Configuration.ConfigurationSettings.AppSettings[“ServiceUrl”];


all the parameters above and below I added to my custom Webservice web.config file:

<!–add key=….–>

You can either chosse the list name or the GUID of the list. YOu find the GIUD in the URL when opening the setting of the list or use the SP Designer to access the proper aspx page.


In the aspx page you also find the list view ID. So if you wanna access a view with a field which is not included in your custom list then you receive an error. I prefer creating my own Webservice View, with all the neccessary fields.

XmlDocument xmlDoc = new XmlDocument();
/*Use the CreateElement method of the document object to create elements for the parameters that use XML.*/
string listName = System.Configuration.ConfigurationSettings.AppSettings[“ListName“];

string strBatch = “<Method ID=’1′ Cmd=’New’>” +
“<Field Name=’ID’>New</Field>” +
“<Field Name=’Attachments’>1</Field>” +
“<Field Name=’Email’>” + contact.Email + “</Field>” +
“<Field Name=’Message’>” + contact.Nachricht + “</Field>” +
//”<Field ReadOnly=’TRUE’ Name=’Timestamp’ Type=’DateTime’ DateOnly=’FALSE’ FromBaseType=’TRUE’ ></Field>” +

XmlElement element = xmlDoc.CreateElement(“Batch”);
element.SetAttribute(“OnError”, “Continue”);
element.SetAttribute(“PreCalc”, “TRUE”);
element.SetAttribute(“ListVersion”, “1”);
element.SetAttribute(“ViewName”, null);

element.InnerXml = strBatch.ToString();
//Parameter 1: Name of the MOSS List
XmlNode return_node = this.ReturnService.UpdateListItems(listName, element);
if (return_node.InnerText == “0x00000000”)
return true;
return false;

catch (SoapException sex)
throw (sex);


In this example I added a dummy user with contribute permissions to my custom list. If you give him less permission you receive an error when the Method wants to update or insert an item in the list.

I receive an object from a WebFormular called Contact with all the attributes. In the above CAML you see CMD=new this when you wanna create a new item.

Use a System.Xml.XmlElement object to create a Batch element in Collaborative Application Markup Language (CAML) that can contain multiple Method elements, and use the UpdateListItems method to post the methods and update items. The Cmd attribute of each Method element determines the operation that is performed on an item by specifying one of the following values:

  • Delete — Delete an item.
  • New — Create an item.
  • Update — Modify an item.

Most of the methods from the SharePoint Web services return XmlNode objects. An XmlNode object represents a node in an XML file, plus all of its children, but it isn’t a full XML document. You can use various methods to parse information from an XmlNode.

One of the most important pieces of data being returned is the GUID that uniquely identifies each list within SharePoint Services. This GUID represents the unique identity of the SharePoint list. From putting together this quick sample though I’ve found that title should be just title!  I may well update this article with a better explanation! The message box that is displayed at the end of the code should show 0x00000000 if your item has been successfully added to the list, or report the problem if it can’t.
Return Value of the Webservice

An XMLDATA fragment in the following form that shows the status of each method block posted through the updates parameter and that can be assigned to a System.Xml.XmlNode object. For items successfully updated, a row fragment is returned with the updated row values.

<Results xmlns="">
   <Result ID="1,Update">
      <z:row ows_ID="4" ows_Title="Title" ows_Modified="2003-06-19 20:31:21"
         ows_Created="2003-06-18 10:15:58" ows_Author="3;#User1_Display_Name"
         ows_Editor="7;#User2_Display_Name" ows_owshiddenversion="3" ows_Attachments="-1"
         ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title"
         ows_SelectTitle="4" ows_Order="400.000000000000"
         ows_DateColumn="2003-09-04 00:00:00" ows_NumberColumn="791.00000000000000"
         xmlns:z="#RowsetSchema" />

Other example GetListItems WS Method:

Here you have to parse the received DOM XML structure from the GetListItems(). Very importan is the Namespace, whne retreiving the nodes using XPATH.

xmlDoc.Load(new XmlNodeReader(this.getService().GetListItems(listName, viewName, null, null, null, null, null)));
XmlNode child_node = xmlDoc.FirstChild.FirstChild;

List<Video> list_Videos = new List<Video>();

foreach (XmlNode row_node in child_node)
Video video = new Video();
video.Childname = row_node.SelectSingleNode(“@ows_Childname”) != null ? row_node.SelectSingleNode(“@ows_Childname”).Value.Trim() : “”;
video.Description = row_node.SelectSingleNode(“@ows_Description”).Value.Trim();
video.Topic = row_node.SelectSingleNode(“@ows_Topic”).Value.Trim();

XmlNamespaceManager nsmgr = new XmlNamespaceManager(
nsmgr.AddNamespace(“z”, “#RowsetSchema”);
nsmgr.AddNamespace(“rs”, “urn:schemas-microsoft-com:rowset”);
nsmgr.AddNamespace(“rootNS”, “;);
return list_Videos;
catch (Exception ex)
throw (ex);

The SharePoint Web Services

Windows SharePoint Services was being designed and developed during the time when Microsoft was beginning to heavily push Web services. It should be no surprise, then, to find out that you can get at the data in SharePoint through Web services. In fact, there’s not just one Web service involved; there are 16. Here’s a brief rundown of the Web services that a SharePoint server makes available out of the box:

* http://server:5966/_vti_adm/Admin.asmx – Administrative methods such as creating and deleting sites
* http://server/_vti_bin/Alerts.asmx – Methods for working with alerts
* http://server/_vti_bin/DspSts.asmx – Methods for retrieving schemas and data
* http://server/_vti_bin/DWS.asmx – Methods for working with Document Workspaces
* http://server/_vti_bin/Forms.asmx – Methods for working with user interface forms
* http://server/_vti_bin/Imaging.asmx – Methods for working with picture libraries
* http://server/_vti_bin/Lists.asmx – Methods for working with lists
* http://server/_vti_bin/Meetings.asmx – Methods for working with Meeting Workspaces
* http://server/_vti_bin/Permissions.asmx – Methods for working with SharePoint Services security
* http://server/_vti_bin/SiteData.asmx – Methods used by Windows SharePoint Portal Server
* http://server/_vti_bin/Sites.asmx – Contains a single method to retrieve site templates
* http://server/_vti_bin/UserGroup.asmx – Methods for working with users and groups
* http://server/_vti_bin/versions.asmx – Methods for working with file versions
* http://server/_vti_bin/Views.asmx – Methods for working with views of lists
* http://server/_vti_bin/WebPartPages.asmx – Methods for working with Web Parts
* http://server/_vti_bin/Webs.asmx – Methods for working with sites and subsites

To use any of these Web services, replace server with the name of your SharePoint server. Because they’re implemented using ASP.NET code, you can retrieve the matching WSDL file for any service by appending ?WSDL to the end of the URL. When you do so, you’ll discover that each one supports multiple methods, making this one of the richest sets of Web services of any current product. For full information on the available Web methods, download the SharePoint Products and Technologies 2003 SDK.

More Informations:

Shows all SharePoint Webservices

Posted in ASP.NET, CAML, DotNet, MOSS, SOAP, WebServices, XPath | Tagged: , , , , , , | 1 Comment »