Tag Archives: Sharepoint

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.

How To Write In Sharepoint Log File

Recently I came across a requirement to write logs in Sharepoint log files.

Add Microsoft.Office.Server dll in your project, you can find this dll under “Common FilesMicrosoft SharedWeb Server Extensions12ISAPI”.

The log files are found under Common FilesMicrosoft SharedWeb Server Extensions12Log. Following line of code is used to write exception in sharepoint default log file.

[code]Microsoft.Office.Server.Diagnostic.PortalLog.LogString("Exception – {0} – {1} – {2}","User Friendly Message",ex.Message,ex.StackTrace);[/code]

Enjoy Coding 🙂

Impersonation in Sharepoint 07

Often will you come across a situation where we need to write in a document library or a custom list through code. As a new bee to sharepoint we start implementing the code and try executing it, it works fine for user who has Full Control,but fails for user who has limited permission.

So to write in a document library / custom list for user who are having limited permission, we impersonate a user who has write permission.In simple definition “Executing code as another named user.”

To achieve impersonation we Open a web using other’s user loginname.Below is the code to impersonate user.

[code]<br /><br />SPWeb web = SPContext.Current.Web.Site.OpenWeb();<br />SPUser user = web.AllUsers[username];<br />SPUserToken userToken = user.UserToken;<br />SPSite site = new SPSite(SPContext.Current.Web.Site.Url.ToString(), userToken);<br />web = site.OpenWeb();<br /><br />[/code]

Drop me a mail if any query.