Monday, May 31, 2010

Finally result is out

Hi All,

Finally result is out.

Looks like many of them have started using VS 2010 and SharePoint 2010 and many of them have not yet.

Thursday, May 27, 2010

Workflow comparison of SharePoint Designer and Visual studio

Hi All,

We all know that we can create workflows using SharePoint designer as well as visual studio. However there are so many differences between creating workflow in each of them.

Let us explore the difference between SPD workflow and VS workflow.

Wednesday, May 26, 2010

Download attachments from list item using web service

Hi All,

In this post, I will show you the way how to get the list attachments using SharePoint web services. There can be one or more attachment attached to the list item of any list in the site.

For example, I have one Dummy List in the site and I have one list item with two attachments. See the figure below.

Now write down the following code. DownloadListItems is the lists.asmx web service of SharePoint. Change the site url reference for your code.

private void button8_Click(object sender, EventArgs e)
DownloadListItems.Lists objLists = new EncryptAndDecrypt.DownloadListItems.Lists();

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

objLists.Url = "{site-url}/_vti_bin/lists.asmx";

XmlNode node = objLists.GetAttachmentCollection("DummyList", "7");

DataSet ds = new DataSet();
using (XmlNodeReader reader = new XmlNodeReader(node))

DataTable dtAttachment = ds.Tables[0];

for (int iCnt = 0; iCnt <= dtAttachment.Rows.Count - 1; iCnt++)
string sourceUrl = Convert.ToString(dtAttachment.Rows[iCnt]["Attachment_Text"]);

int strLastIndx = sourceUrl.LastIndexOf(@"/");

string FileName = sourceUrl.Substring(strLastIndx + 1);

using (WebClient client = new WebClient())
client.UseDefaultCredentials = true;
byte[] response = client.DownloadData(sourceUrl);

FileStream fStream = new FileStream(@"C:\DummyListAttachments\" + FileName, FileMode.Create, FileAccess.ReadWrite);
fStream.Write(response, 0, response.Length);




As you can see first we have taken the reference of the Lists.asmx service and then passed the credentials. Change it to your credentials according to your need. Then we called getattachmentcollection method, and simple got the attachments in the form of XMLNode.

We actually get path only, not the real attachments. For simplicity I have converted that XMlnode into to data table so that we get the Attachment table and attachment_xml column with values as direct path to the attachment with complete URL of the site.

And then finally we use WebClient method to pull those documents to our local drive.

Very simple and easy way to get the attachments from list item. What say?

Monday, May 24, 2010

Attach file to list item programmatically using web service

Hi All,

In SharePoint if we want to attach a file to any existing list item and we are in any other or client / server application or just any other console application, then we can use SharePoint web services to attach a file to existing list item.

Here is a sample code to attach a file to existing list item.

Write down the below code and you are good to go. Just see the argument of addattachment method of lists.asmx web service. In my case, I am attaching my file to item which has ID 7.

See image before running this code.

private void button7_Click(object sender, EventArgs e)
string strFilePath= textBox1.Text;

if (!File.Exists(strFilePath))
throw new ArgumentException(String.Format("{0} does not exist",
strFilePath), "srcUrl");

FileStream Stream = File.OpenRead(strFilePath);
string fileName = Stream.Name.Substring(3);
byte[] contents = new byte[Stream.Length];
Stream.Read(contents, 0, (int)Stream.Length);

DownloadListItems.Lists objLists = new EncryptAndDecrypt.DownloadListItems.Lists();

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

objLists.Url = "{site url}/_vti_bin/lists.asmx";

string addAttach = objLists.AddAttachment("DummyList", "7", fileName, contents);


catch (System.Web.Services.Protocols.SoapException ex)



See below image after running above code.

That is it. you have just attached your file to the existing list item.

Wednesday, May 19, 2010

Office 2010: The movie

Hay guys,

Just check this video.

its about new Office 2010

you will definitely like it

and it will create your more interest towards Microsoft...:)

And for more video check this site

Tuesday, May 18, 2010

SharePoint 2010 features and enhancements

Hi All,

I am really very happy to share with you all new and enhanced features in new SharePoint Server 2010. Apart from sharing initial thought in SharePoint 2010 is coming, I would like to go in bit details now as SharePoint 2010 has finally released and available for use.

Office 2010 + SharePoint 2010 global launch

Let us explore its features one by one.

BCS (Business Connectivity Service)

• A business connectivity service is a replacement of Business data catalog (BDC) in MOSS 2007. Earlier we used BDC to fetch the data from different external sources and display in SharePoint 2007 with the help of different web parts. However the limitation was that it was a read only operation. We could select records only. Now in BCS it will be completely CRUD operations. You can insert, retrieve, update and delete the record from SharePoint 2010. Another big advantage of BCS is unlike BDC, you no need to buy enterprise edition to get this. You can also create lists based on database tables now with the help of BCS.

Developing enhancements
• In SharePoint 2007, development effort goes in the server operating system. Now in SPS 2010 it will be possible to develop solutions in client OS like Windows 7. Developer can now use .Net framework 3.5 LINQ feature directly to query lists and document library. However the current method of using SPQuery still exists and exists with some enhancements. New ribbon interface enabled developer to learn a new client side model for SharePoint 2010. Visual studio 2010 plays a great role in making developer’s life easier. Control is returned to user even though event handler has not completed. Now we have a full control over this behavior to make sure that event handler completes its execution and then transfer control to user. This will solve lot of problems.

Enhancement in large list
• We all know that the first question people used to ask is what if the data is enormous; can we store it in the list? Well, now Microsoft has really worked very hard on this feature to make it more effective. New features have come up for this issue and they are Query Throttling, Batch Query Support, Remote Blob Storage, and External Lists. Query throttling allows administrator to control over the returning result from the list. If you query the list and if the result returns more than 3500 rows, then admin can restrict this limit. Now SharePoint also includes handling of simultaneous multiple items in a single batch. It also allows storing some large files, like large picture or audio / video files outside of SharePoint with the help of remote blob storage.

Improvements in Workflow
• Now workflows can be saved as template. This is really a significant change, because in earlier version as an out of the box workflows, they are associated with list and hence limits the association. Now we have the template workflows, and so we can attach it to any list in SharePoint Designer 2010. Moreover, now we can also modify existing out of the box workflows which ships with SharePoint 2010.

Access Services and Visio services
• As we had the excel services in SharePoint 2007, we now have access services as well as vision services. User now can create vision diagrams and can publish them directly in SharePoint 2010. And the end user does not need to have client vision to see the diagram. End user can see it right from SharePoint 2010. In the same way access services allows publishing access applications to SharePoint which is again a fantastic move and very useful move. Of course, these services will have some limitations as they will work in browser same like excel services. You will not get all full features like client access or client vision, however a fair enough improvement.

Record management enhancement
• We all are aware about the record management feature of MOSS 2007. Now this feature has been enhanced in SPS 2010. Now document can be routed to multiple repositories and that too in hierarchical manner. Now in document library we can mark the document as a record instead of moving the document to a record repository.

Tagging and cloud
• In SPS 2010 we can tag sites, blogs, list and documents. Almost every element is tagging enabled in SPS 2010. Rating is also one of the new features in SPS 2010. We can rate artifacts and also recommend to others.

Security and Deployment
• In SPS 2010 they have introduced a new concept called sandbox solutions. Now administrator can decide on which part of code can run on what constrain. There can be some part which strictly requires administrator privileges to run. Ultimately administrator can enforce a security on what resources can be consumed by code. There are three ways to deploy our code now on the server.

1) Full trust – DLL is deployed in GAC.
2) Partial trust – DLL is deployed in bin directory of web application.
3) Sandbox – DLL is deployed in site collection gallery.

As and when we come across to new features, we would love to share it with our readers

Monday, May 17, 2010

Finally the result is out

Hi All,

Yet another result is out. We asked if you have observed significant change in SharePoint Designer 2010 and here is what people thought.

Friday, May 14, 2010

Required field using jQuery in Newform and EditForm

Hi All,

May times there are requirements like we need to define a field as a required field in SharePoint. Yes, you will say what is new with that? This is built in feature of SharePoint.

Ok, what if I say that field should be mandatory while updating list item but not while inserting the list item. What if I say if value of one drop down in xyz, abc field becomes mandatory?

Well, in scenarios like this we can use jQuery. Yes, jQuery is the answer to this question. Let us put this in to a real scenario.

Ok, before getting into this, I would like to share some steps about this. First we need to handle the change event of drop down. Then we will check the value of the drop down, if the value is suspended, we will pop up one message saying that now because you have selected Suspend status, you must mention the reason for this and we will disable the button OK. We have to do this because there is no way we can stop user clicking ok button unless user writes the reason. Otherwise item will be updated which we do not want.

we also need to handle lost focus event of text area, and at the end we will count the number of characters in the text area. If total comes to zero, well then keep button disabled. If it is not zero and more than zero, then we will enable the button.

Or else we can ask user to select Status back to value which was earlier and enable the button.

Yes, this all steps are required. Try for yourself and you will realize that yes these all steps are required. It may look like some lengthy solution, But remember we did all this stuff right on browser. We never went to write down the code in event handler (this stuff really annoy the end user, as it takes to a different error page, or creating any custom field for this. This is what we wanted and this is the power of jQuery. Isn’t it.

Ok, let us see now in practical

First add the content editor web part above the New Form or Edit Form LVWP where ever you want to place the logic.

This is the layout of my editform.

Add the following code to the content editor web part. Do not forget to reference appropriate jquery file from your library.

<script type="text/javascript" src="{site URL}/Shared%20Documents/jquery-latest.js">

$(document).ready(function() {
//Below function makes sure that if the status is not suspended in edit mode, it disables the reason text //area
var text = $("select[title$='Status'] :selected").text();
if(text != "Suspended")
$("textarea[title$='Reason'] ").attr('disabled', true);


Below function makes sure that when the status drop down is changed to suspended status, reason textarea becomes enabling to write down the result and disabled the OK button unless user enters the reason. If suspend is not selected, again disable the reason field and enable the OK button.


var text = $("select[title$='Status'] :selected").text();

if(text == "Suspended")
alert('you must provide reason for suspending this order');
$("input[value$='OK']").attr('disabled', true);
$("textarea[title$='Reason'] ").attr('disabled', false);
$("input[value$='OK']").attr('disabled', false);
$("textarea[title$='Reason'] ").attr('disabled', true);


Finally below is the blur event of the reason field, which checks if anything is entered in reason field or not. If not keep the button OK disabled, or else if something is written enable the button.


var text = $("textarea[title$='Reason'] ").text();

if(text.length <= 0)
$("input[value$='OK']").attr('disabled', true);
$("input[value$='OK']").attr('disabled', false);




So here is the result of it.

See below image as status is not suspended I am not able to type in anything in reason field.

Below figure shows when I changed the status to Suspended, it pops up message and disabled the ok button after message is displayed.

After mentioning the reason, OK button enables.

That is it. You have just made required field validation without using any custom field or writing event handler.

Wednesday, May 12, 2010

Adding list item to List using web service

Hi All,

In this post, I will show you how to add list item to the list using SharePoint web service.

I am writing a code in Windows Application and I have taken reference of Lists.asmx of respective site.

I have DummyList as list in my site and in that I have three columns. Name of the columns are title, group which is Choice column (GroupA,groupB,groupC) and Price which is number.

private void button6_Click(object sender, EventArgs e)
string strQuery = "<Method ID='1' Cmd='New'>" +
"<Field Name='Title'>" + "Title Test" + "</Field>" +
"<Field Name='Price'>" + 12000 + "</Field>" +
"<Field Name='Group'>" + "GroupB" + "</Field></Method>";

DownloadListItems.Lists objLists = new EncryptAndDecrypt.DownloadListItems.Lists();

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

objLists.Url = "{site url}/_vti_bin/lists.asmx";

String listName = "DummyList";

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

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

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

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

elBatch.InnerXml = strQuery;

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

string result = ndReturn.OuterXml.ToString();


Just make sure that you pass proper credentials to the web service. Rest the code itself is self explanatory.

Just observe the result string above, and see ErrorCode element in it, it should be 0x00000000. If it is, then it is a success, else there is some error and item has not been added.

That is it. You have just added list item using web service.

------Modified on 21-05-2010-----------

Let us explore bit more on the same post. We will now add lookup field through web service. Yes, this is bit different than adding the simple field using web service.

We will take the same example as we show above.

I have made a little change in the list settings. I removed the Group column and recreated the same with lookup column to another list with same values. I have another list which has GroupA, GroupB and GroupC as title values in it. And then in DummyList I’ve created that lookup field.

So now let us move on. There are two ways you can insert lookup field through web service. Either you can mention in Field tag that this is the lookup field or you can directly reference that look up value by mentioning; # sign in between.

Below are the examples that describe both the ways.

1) "<Field Name='Group' Type='Lookup'>" + 2 + "</Field></Method>";

2) "<Field Name='Group'>" + "2;#GroupB" + "</Field></Method>";

Where first is mentioning field is lookup and second mentioning ID + ItemName in it. ID is the ID for the item in master list from which we have taken the reference. In my case GroupB’s ID in master list is two.

Modify the above code and then let’s run this sample now. See the result. Make sure that if anything is wrong, observe the result and in that check the ErrorCode element, you will see some error code in that. If there is not error, then as I mentioned earlier it will return you 0x00000000.

One interesting fact is, I don’t know how accurate this is but even in second way, you write like “2;#GoupC”, then also it will insert GroupB as it takes ID as the main value. Does it mean that we can specify any value after ;# sign as far as that value is present in the master list and that will not impact on what you want to insert??

Humm..interesting. I recommend make sure to query your master list with lookup value and get the ID and then combince that ID + “;#” + value and thenuse it in this method to populate your list lookup column.

I'll keep you all posted on what's more with List Item using SharePoint web service.

Monday, May 10, 2010

Upload document to document library using web service

Hi All,

Today we will see how to upload document to the document library using its web services. May times we need this feature from any ASP.NET application or just any other java application to upload document to the document library.

That is why SharePoint web services come into the picture.

Here is a simple way you can upload the document.

I have one windows application created and for demo purpose, I am writing a code directly in button click event.

You need to reference copy.aspx web service. Here DownLoadSharePointDocument is the name of web reference name.

private void button5_Click(object sender, EventArgs e)
DownloadSharePointDocument.Copy copyService = new EncryptAndDecrypt.DownloadSharePointDocument.Copy();

copyService.Url = "{url}/" + "_vti_bin/copy.asmx";

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

string[] DestinationUrl = (“url goes here” };
string strSource = @"C:\SmartSurvey.pdf";

DownloadSharePointDocument.CopyResult FirstResult = new DownloadSharePointDocument.CopyResult();
DownloadSharePointDocument.CopyResult SecondResult = new DownloadSharePointDocument.CopyResult();
DownloadSharePointDocument.CopyResult[] ArrayOfResult = { FirstResult, SecondResult };
DownloadSharePointDocument.FieldInformation fFiledInfo = new DownloadSharePointDocument.FieldInformation();
fFiledInfo.DisplayName = "Description";
fFiledInfo.Type = DownloadSharePointDocument.FieldType.Text;
fFiledInfo.Value = "This is the test description";
DownloadSharePointDocument.FieldInformation[] fFiledInfoArray = { fFiledInfo };

FileStream objStream = new FileStream(strSource, FileMode.Open, FileAccess.Read);
byte[] Contents = new Byte[objStream.Length];
byte[] r = new Byte[objStream.Length];
int Read= objStream.Read(Contents, 0, Convert.ToInt32(objStream.Length));

uint copyresult = copyService.CopyIntoItems(strSource, DestinationUrl, fFiledInfoArray, Contents, out ArrayOfResult);


Make sure that you pass proper administrative credentials while passing the network credentials.

return value of uint should be zero to indicate a success. if it is not zero, then something is wrong and document will not upload successfully.

That is it. You have just uploaded the document to the document library.

Friday, May 7, 2010

Download all documents recursively from document library using web service

Hi All,

A SharePoint web service is such a fantastic mean of providing a value to the non SharePoint using applications.

When in any ASP.Net or just any other application needs to use SharePoint library or any other feature, they can use SharePoint web services. And classic example and a common requirement are to download al documents in all folders recursively using web services.

Well, how difficult it is? Answer is that the question is wrong. Ask how easy it is? Well, very easy.

Just take the reference of SharePoint Web Service that you want to work with.

Just for the demo, I have created windows application and used a Lists.asmx web services to pull all documents from all folders within document library.

Here is a simple code for this. On one button click I am copying all files from document library. Just make sure that you change appropriate URL of your site. Also make sure if it is the sub site, then your lists.asmx should point till the sub site path. That means {subsite url} + “/vti_bin/Lists.asmx”;

private void button3_Click(object sender, EventArgs e)
XmlDocument xmldoc = new System.Xml.XmlDocument();

string URL = "";

string FileName = "";

DownloadListItems.Lists objLists = new EncryptAndDecrypt.DownloadListItems.Lists();

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

objLists.Url = "{siteurl}/_vti_bin/lists.asmx";

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

XmlNode xmlQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");

XmlNode xmlViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");

XmlNode xmlQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");

xmlQueryOptions.InnerXml = "<ViewAttributes Scope='RecursiveAll' IncludeRootFolder='True' />";

xmlViewFields.InnerXml = "";

xmlQuery.InnerXml = "";


XmlNode xmlListItems = objLists.GetListItems("Shared Documents", null, xmlQuery, xmlViewFields, null, xmlQueryOptions, null); //change the document library name to your document library

XmlNodeList oNodes = xmlListItems.ChildNodes;

foreach (XmlNode node in oNodes)
XmlNodeReader Reader = new XmlNodeReader(node);

while (Reader.Read())
if (Reader["ows_EncodedAbsUrl"] != null && Reader["ows_LinkFilename"] != null)
URL = Reader["ows_EncodedAbsUrl"].ToString();

FileName = Reader["ows_LinkFilename"].ToString();

CopyAndSaveAttachment(URL, FileName);




catch (System.Web.Services.Protocols.SoapException ex)
throw ex;


public static void CopyAndSaveAttachment(string URL, string FileName)

HttpWebRequest request;

HttpWebResponse response = null;


request = (HttpWebRequest)WebRequest.Create(URL);

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

request.Timeout = 10000;

request.AllowWriteStreamBuffering = false;

response = (HttpWebResponse)request.GetResponse();

Stream s = response.GetResponseStream();

//Write to disk

FileStream fs = new FileStream(@"C:\DownLoads\" + FileName, FileMode.Create);

byte[] read = new byte[4096];

int count = s.Read(read, 0, read.Length);

while (count > 0)

fs.Write(read, 0, count);

count = s.Read(read, 0, read.Length);


//Close everything





catch (Exception ex)
throw ex;



That is it. You are done with downloading all documents from document library recursively.

Wednesday, May 5, 2010

Download document from SharePoint library using web service

Hi All,

Many times we come across to a situation where in we need to download the document, PowerPoint files, excel files or just any other file from SharePoint.

However we are not on the server or let’s say we need to show those documents in some ASP.Net application and show their content on some ASP.Net page.

At that time we need to use the web service provided by SharePoint and then we are able to download any document from any document library in the site.

Following is the simple code that you need to write to pull the document to your local machine.

First add the web reference and then add URL of your SharePoint server + “_vti_bin/copy.asmx"”.

Then give it a proper name, so that you can reference in the code.

Then write down simple code shown below. In this example I am downloading simple ppts file from SharePoint server and copying it in C drive. I am passing default credential as I am in the same domain connected with windows authentication. However if you are not connected, then pass the user name and password of administrator who has a permission over the site.

Here DownloadSharePointDocument is the name of my web reference proxy class.

DownloadSharePointDocument.Copy copyService = new EncryptAndDecrypt.DownloadSharePointDocument.Copy();

copyService.Url = "" + "_vti_bin/copy.asmx";

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

string sourceUrl = “{server url} + {document lib name} + {file name}”;
string destinationUrl = @"C:\\Downloaded.ppsx"; // location where file to be downloaded

DownloadSharePointDocument.FieldInformation fieldInfo = new DownloadSharePointDocument.FieldInformation();

DownloadSharePointDocument.FieldInformation[] fieldInfoArray = { fieldInfo };
DownloadSharePointDocument.CopyResult cResult1 = new DownloadSharePointDocument.CopyResult();
DownloadSharePointDocument.CopyResult cResult2 = new DownloadSharePointDocument.CopyResult();
DownloadSharePointDocument.CopyResult[] cResultArray = { cResult1, cResult2 };

byte[] fileContents = new Byte[4096];
copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents);
FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
fStream.Write(fileContents, 0, fileContents.Length);

That is it. now you have the document in your machine.

Monday, May 3, 2010

Limitation of SharePoint Designer workflow

Hi All,

We all know the power of SharePoint Designer. When there is any requirement in which we need to send a mail when item is added to list or document library along with its metadata column values and with some formatting.

However I observed one simple limitation of designer workflow. We can add field values in the body part when we want to send an email from designer workflow. However when it comes to the subject line, we cannot add some static text and field value together. It can be wither entirely static subject line or it can be entirely a field values.

So how should we overcome this difficulty? Well, the idea is have one calculated field and define its value with “static text” & [field value] and when sending mail from designer, mention this calculated field in subject line.

You are ready to send a customized subject line.

Hope this post will help you.

---------Updated on 21-05-2010----------------

I would like to highlight few more limitations in Workflow designer.

We do not have facility to add bcc field.

We cannot deploy designer workflow created in local machine to staging or production environment easily.

We cannot set a priority of an email.

There is no HTML editing capability in body text. Hence we are bound to write manually all html tags and formatting stuff. This is really a big limitation I would think.

Let’s say, you are sending an email and then you include field values in the body of the email. If any field has no value, means if the string is empty, Designer workflow inserts “??????” (Yes, six question marks) in that. Now this is really a strange behavior and totally unexpected one.

Sunday, May 2, 2010

The Result is out

Hi All,

We have asked in poll question if you have used and observed any significant change in windows workflow foundation 4.0.

It looks like still people have not started using it.

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to