Interacting with SharePoint using WebService

In a typical developer guide, one will interact with SharePoint using SharePoint object model, i.e.  Using SharePoint libraries and then deploying code on SharePoint server.

However ever wondered what if one will not have execute permission on SharePoint server and still need to build a webpage which will be hosted on SharePoint and pulls data from libraries?

Here SharePoint Web services comes to rescue, SharePoint has their built-in Web service which allows users to access data without using SharePoint libraries. These Web service are usually found at http://<server-url>/_vti_bin/lists.asmx one can either add them as web reference or consume them using JavaScript Ajax

Below are some web services data which I managed to pull out.

Web Services Description URL
Administration Service This Web service provides administrative capabilities like creating a new top-level site, deleting a top-level site and getting the list of available languages. http:///_vti_adm/admin.asmx
Alerts Service Provides access to the list of active alerts and allows to delete active alerts. http:///_vti_bin/alerts.asmx
Document Workspace Service This Web service is used to manage Document Workspace sites. It allows you to create new document workspaces, delete document workspaces, create new sub-folders, delete sub-folders, and so forth. http:///_vti_bin/dws.asmx
Forms Service Each list has forms associated which are used to display list items, create new list items, and update or delete existing list items. This Web service allows to get the collection of forms associated with a list and then get detailed information about each form. http:///_vti_bin/forms.asmx
Imaging Service SharePoint has picture libraries that users can use to manage pictures. This Web service allows to upload pictures, download pictures, create new folders, delete folders and pictures, and the like. http:///_vti_bin/imaging.asmx
List Data Retrieval Service Allows you to run XPath like queries against a list. http:///_vti_bin/dspsts.asmx
Lists Service This Web service is used to work with lists and list data. You can obtain the collection of lists, add new lists, remove lists, add new list attachments, remove attachments, and so on. http:///_vti_bin/lists.asmx
Meetings Service This Web service is used to work with Meeting Workspaces. You can create a new Meeting workspace, remove an existing Meeting workspace, add new meetings, add new meetings using ICal files, and so forth. http:///_vti_bin/meetings.asmx
Permissions Service Sites and lists have permissions assigned to them. This Web service is used to obtain the permissions assigned to a list or site, add new permissions, and update or removing existing permissions. http:///_vti_bin/permissions.asmx
Site Data Service The Site Data Web service can be used to return meta-data about a site or list, get the collection of lists, get the attachments for a list item, get the collection of items in a list, and so on. http:///_vti_bin/sitedata.asmx
Site Service This Web service can be used to return the list of site templates. When you create a new site using the Administration Web service you need to specify the site template name to use that you can obtain through this Web service. http:///_vti_bin/sites.asmx
Users and Groups Service This Web service is used to work with users, site-groups and cross-site groups. You can add, update or remove users, site-groups, and cross-site groups. You can also add users or cross-site-groups to a site-group. http:///_vti_bin/usergroup.asmx
Versions Service Document Libraries and Picture Libraries can have versioning enabled, which stores a copy of every single file version. This Web service can be used to get the list of available versions, delete versions, and also restore a file version. http:///_vti_bin/versions.asmx
Views Service Lists have views associated that define what fields are shown, what filtering and sorting is applied, what grouping is applied, and so on. This Web service is used to work with list views. You can get the collection of views, add new views, remove views, update the Html code used to display a view, and the like. http:///_vti_bin/views
Web Part Pages Service Web Parts are objects that you can place on Web part pages. This Web service is used to work with Web parts and Web part pages. You can get the list of Web parts on a page, you can add or remove Web parts, and so forth. http:///_vti_bin/webpartpages.asmx
Webs Service This Web service is used to work with sites and sub-sites. You can get the list of list-templates, get meta-data about a sub-site, get the list of sub-sites, and so on. http:///_vti_bin/webs.asmx

These Web service interfaces make it very easy to integrate SharePoint capabilities right into your application.

Updating database using dataset

This topic illustrates how to update data in a database using a DataSet. It is important to remember that you can also insert, update, and delete data in a database directly using a SqlCommand.

Once the DataSet is loaded, you can modify the data, and the DataSet will track the changes.

The DataSet can be considered an in-memory cache of data retrieved from a database. The DataSet consists of a collection of tables, relationships, and constraints. In this example we will show how to use the Delete method on the DataSet to Delete rows from the database.The Database values are updated with those from Dataset using Update method of SqlDataAdapter

Below are some simple steps to preform  Delete operation on Dataset.

STEP  1 : Fill the Dataset with the data you required and bind it to grid.

STEP 2: To Delete a particular row from dataset we required its DatasetIndex, to know the DatasetIndex we perform the delete operation on Grid’s ItemCommand Event.

[code]
If e.CommandName = "Delete" Then
parentset.Tables(0).Rows(e.Item.DataSetIndex).Delete()
End If
dgUser.DataSource = UpdateDatabase(parentset, "OleDb")
dgUser.DataBind()
[/code]

STEP 3: Create a new instance of OleDbDataAdapter and pass the required parameters, you can either pass OleDbCommand object or write down the Sql statement alongwith the ConnectionString.

Create a instance of OleDbCommandBuilder, it is used to update the changes from Dataset to Database. The parameter required for OleDbCommandBuilder is OleDbDataAdapter with a SELECT Sql statement. The command builder will automatically generate INSERT,UPDATE & DELETE statements for the table and parameters used in SELECT statement.

[code]
Public Function UpdateDatabase(ByRef dataSet As DataSet, ByVal Provider As String) As DataSet
If Provider = "OleDb" Then
Dim dbAdapter As New OleDbDataAdapter("SELECT Sql Statement",ConnectionString)
Dim objCommandBldr As New OleDbCommandBuilder(dbAdapter)
dbAdapter.Update(dataSet)
ElseIf Provider = "SQL" Then
Dim sqlAdapter As New SqlDataAdapter("SELECT Sql Statement",ConnectionString)
Dim sqlCommandBuilder As New SqlCommandBuilder(sqlAdapter)
sqlAdapter.Update(dataSet)
End If

Return dataSet
[/code]

STEP 4: Build & Execute.

Here is the link to download the sample application which will demonstrate the above behavior.

You can also find a detailed explanation of Updating Database using Dataset over here.

Enjoy Coding and Keep Learning 🙂

Insert Code Snippet – Tip Of Week#1

Hi guys, do you know you can use already ready code inside your visual studio? Yes certainly you can insert code snippets into your code. You can invoke the “Insert Snippet” by using shortcut “ctrl k + ctrl x”

Be Sunshine Happy :)

What makes some people simile and stay sunshine happy, almost all the time? These optimists refuse to get crushed by bad news and spread the sounds of laughter and hope. They are all around us, trying to give those who’re sulking, frowning and sad, a simple lesson in the pursuit of happyness.

Most people are happy if their wishlist is fulfilled. But that’s not real happiness. It’s a fluctuating happiness index which dips if they fall ill or experience heartbreak. Happy energy wouldn’t be dependent on outside factors, it has to come from within. There are people, who have everything they desire and are still unhappy. Choose your emotions and thoughts. Free yourself from past baggage, mistakes and regrets. Choose to be happy.

There’s something about being genuinely happy. Why should your happiness be dependent on tha global economy, your work environment or your spouse’s behaviour?

Moods sway from dark to happy for everyone. Everyone has the power to be totally happy, which is a cultivated art. Can you be really happy in tough times?

Optimism has nothing to do with the future, rather, it is a description of reality. The real definition of optimism was relevent in good and bad times, you just have to choose to be happy, despite whatever happens.

Live life to full, never pay attention to failures. Every minute whatever you do, you should enjoy by saying yes more than by saying no. Always have faith that’s the way to open doors. Once you decide you’ll be happy, that’s what you ‘ll create in your life.

For optimists all experiences are positive, as they bring new opportunity. Hence, happiness is a decision.

Don’t label situations good or bad. When unhappiness onfronts you, rather than running away, exercise the force of will to run through it. It’s not just in thought but in action too. If you have to experiment with new ideas, you’ll experience setbacks. you should not let it intimidate or overwhelm you. Have the will to be happy from inside.

The way to bring happiness is to work honestly and to share. Ther has to be a sense of detachment from external situations.

Work on happiness as a skill to be developed. Let happines be a learnt reaction. You’ll have to work at being happy. But it’ll be rewarding and bring you real joy.

Tell yourself every minute. “It’s in my power to be happy, no matter what!”

How to be Sunshine Happy,

– Don’t label situations or experiences as good or bad.

– Empower yourself to be happy.

– Look within for happiness

– Don’t get affected by bad news

– Choose your emotions. Keep saying, ‘I choose to be happy’

– Conserve your energy, don’t let people sap it

– If you’re hurt, don’t be dependent on anyone else to heal

– Don’t indulge in hurt

– Don’t be imprisoned in you past or have self-pity

Using ParseQueryString to get QueryString Values

Following is the sample code you can use to parse your querystring and return NameValueCollection

[code]

protected void Page_Load(object sender, EventArgs e)
{
String currurl = HttpContext.Current.Request.RawUrl;
String querystring = null ;

// Check to make sure some query string variables
// exist and if not add some and redirect.
int iqs = currurl.IndexOf(‘?’);
if (iqs == -1)
{
String redirecturl = currurl + "?var1=1&var2=2+2%2f3&var1=3";
Response.Redirect(redirecturl, true);
}
// If query string variables exist, put them in
// a string.
else if (iqs >= 0)
{
querystring = (iqs < currurl.Length – 1) ? currurl.Substring(iqs + 1) : String.Empty;
}

// Parse the query string variables into a NameValueCollection.
NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

// Iterate through the collection.
StringBuilder sb = new StringBuilder("");
foreach (String s in qscoll.AllKeys)
{
sb.Append(s + " – " + qscoll[s] + "");
}

// Write the result to a label.
ParseOutput.Text = sb.ToString();

}

[/code]

This is the front end code ,

[code]

<form id="form1" runat="server">
Query string variables are:
<asp:label id="ParseOutput" runat="server">
</asp:label></form>

[/code]

Hope this Helps 🙂