A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Thursday, November 30, 2006

White paper discussing explorer view problem


Explorer view has always been a problem for users. Microsoft has recently released a white paper that discusses this problem in great detail. It can be downloaded from the following link:
Published Thursday, November 30, 2006

WSUploadService - Web Service for uploading documents into SharePoint

WSUploadService - Web Service for uploading documents into SharePoint

WSUploadService - Web Service for uploading documents into SharePoint
Category: MOSS 2007, WSS 3.0
WS UploadService is a web service written for Microsoft Office SharePoint Server 2007 and Windows SharePoint Services 3.0 and is meant for uploading documents into SharePoint. I have just uploaded the zip file to GotDotNet.com so it will take some time before the zip file appears in the list of downloads. For the time being, you can download the zip file from the following location:
http://www.walisystems.com/ws1_dlc.asp (Download Size: 361 KB)
The zip file contains the web service and its related files. It also contains an installer to help you install the service easily on your server. Unzip the file to your hard disk. It will create a "WSUploadService" folder. You can unzip the file anywhere on your hard disk. There is no restriction on unzipping it to a particular folder. Run "UploadServiceCopier.exe" to install the service. Installer will ask you to select a SharePoint site where this service should be installed. Select your site from the drop down and keep the folder name as "bin" (second field: textbox) and click "Next".

To uninstall, run the "UploadServiceCopier.exe" again. It will give you the following message:

"Service is already installed. Do you want to uninstall it?"

Select "Yes" and then select "Remove WSUploadService" and click "Finish" to uninstall the service. Uninstall will remove all copied files from your hard disk.

Point to remember:

1. Please run "UploadServiceCopier.exe" to install/uninstall the service. Do not run "setup.exe" directly as it will not install the service correctly.

Sample Application:          

Following is a C# sample demonstrating the use of this web service.

1. Create a .NET application.
2. Add a web reference to the web service installed on your server. For example, if you installed the web service on your default port (80), then use following url to access the web service:


If you installed the service on another port, for example, port 17316, then the url will be:


You can also browse all web services available on the server. Files.asmx will be listed in the web services available on the server. There will be multiple entries, each entry representing the service available for a different web application. Therefore, if you want to upload documents to a site on port 80, then you should select Files.asmx for port 80.

3. Add following code to your application:

localhost.Files oUploader = new localhost.Files();

oUploader.PreAuthenticate = true;
oUploader.Credentials = CredentialCache.DefaultCredentials;

string strPath = @"C: est.doc";
string strFile = strPath.Substring(strPath.LastIndexOf("\") + 1);

string strDestination = "http://sp:17316/Docs";

FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 0, (int)fStream.Length);

string str = oUploader.UploadDocument(strFile, binFile, strDestination);

catch (Exception ex)
MessageBox.Show(ex.Source + " - " + ex.Message + " - " + ex.InnerException + " - " + ex.StackTrace);

localhost is the name of the web reference that you added in previous step.

4. Run the application to test the service. "strPath" contains the filename that is to be uploaded. This is just a sample to show you how the service works, that's why i have hard coded the filename but in a real life situation you may want to add a text box and a browse button to select files from your hard disk. "strDestination" contains the destination path. This should be the path representing the document library where file is to be uploaded.

5. Finally, before testing the service, make sure the current user has privileges to upload documents in the destination document library. The user should have "Contributor" rights in the document library otherwise, you will get "401: Unauthorized" error.

Please feel free to send your comments and feedback and keep visiting the blog for more detail on the web service.

Thank you,

S.S. Ahmed

SharePoint Tags: http://del.icio.us/sharepoint
Published Thursday, November 30, 2006 4:07 PM by ssa

Comment Notification

If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using RSS



All About SharePoint said:

December 6, 2006 8:54 AM

All About SharePoint said:

WS Upload Service Demo Using ASP.NET AJAX 1.0 Beta 2

You can download WS UploadService 1.0...
December 7, 2006 11:47 AM

ssa said:

Dear Sahridhayan,

Thanks for your email. The web service must be installed on the server that hosts SharePoint. Because you are trying to add a document to a library on virtual PC1 therefore, web service must be installed on virtual PC1. You can access this web service from any other machine (client). Be it Win 2003 or XP!

Hope this helps!


December 17, 2006 5:56 AM

Sahridhayan said:


Yes, i have my VPC2 installed with WSS 3.0 since i am able to execute  Share point Object model, is that not enough to connect to another sharepoint server using the same web service?

December 17, 2006 8:55 AM

ssa said:


Since you are trying to upload the document to VPC1, therefore, web service must be installed on VPC1.


December 26, 2006 2:41 AM

Sahridhayan said:

Due to some constraint i cannot have web service and SP(production) in single place, cannot i access SP from with in another WS (where WSS3.0) installed?

January 3, 2007 2:22 AM

ssa said:


Of course, you can access SP from any web service but that web service must be running on the server. This is what web services are for. You can access SP from remote machines using web services.
January 10, 2007 4:46 AM

Tuesday, November 21, 2006

SharePoint utility pack

Ishai Sagi has released a free SharePoint utility pack. You can download it here. It has some nice utilities:

1. Delete sites with their sub sites
2. Create lists in a site tree
3. Change field settings for a field - change some of the hidden settings that sharepoint doesnt show you in the interface. for example - should a field be displayed in the "new" form?
4. Deploy web parts - specify a web part, specify a site, specify a zone and whether or not you want to deploy to just that site, or all sites under it.

I tried it today. It's an excellent utility.


Sunday, November 19, 2006

Source code of UploadService (web service)

I  have uploaded UploadService source code on codeplex.com. Original post describing the uploadservice web service is:
Source code can be downloaded from:


Thursday, November 9, 2006

Searching Fileshares in MOSS 2007

Searching Fileshares in MOSS 2007
Searching fileshares in MOSS 2007 is very easy. I always considered this feature to be very useful and this was one of my  favorite features in SPS 2003. Following are the steps (with screenshots) required to create a fileshare in MOSS 2007:
1. Go to "SharePoint Central Administration" and select a "Shared Service" that is associated with the application in which you want to show the results of a fileshare search. You can create a new "Shared Service" as well if you intend to create a new application. You can also associate your existing "Shared Service" with the new (to be created) sites. To do this, go to "Shared Services Administration" and change the default SSP by clicking "Change Default SSP". This will automatically associate your newly created sites with an existing (default) SSP.
2. In your selected SSP, click the "Search Settings" link.
3. In the "Configure Search Settings" page, click the "Content sources" link.
4. In the "Manage Content Sources" page, click the "New Content Source" link.
5. Add a name for your content source in the "Name:" field and select "File Shares" as the content type. In the start address box, add your fileshare. This should be a shared folder, for example, file://sp/test. In this case, "sp" is your machine name and "test" is the shared folder on machine "sp".
6. Check the "Start full crawl of this content source" checkbox and click "OK". "Manage Content Sources" page will show the status as "Crawling Full". Refresh the page and you will notice that the status has been changed to "Idle". Crawling might take some time, depending on the size of the shared folder.
7. Now, go to your SharePoint site and try to find a file using a keyword in the search box. SharePoint will return the file against the keyword you enter.

Writing an event handler for a survey

Writing an event handler for a survey
Make sure event handlers are enabled on the site where your survey is.
1. To enable event handlers for your site, go to "SharePoint Central Administration".
2. Select "Application Management" tab and then select "Web application settings" in "SharePoint Web Application Management" section.
3. Select your web application from the drop down. Click "Change Web Application" and then select your web application from the form that opens.
4. Scroll down and locate the "Event Handlers" section and turn them on.
5. Now go back to your site. You are ready to write an event handler for your survey. I will create an event handler just for the demo purposes. There will be only one question in our survey:
Is MOSS 2007 an excellent product?
Answer to this question is either "Yes" or "No". Type is "Choice" and options are "Yes" and "No". Choices should be displayed as radio buttons.
6. Start a new "Class library" project in VS and select C# as the programming language. Project will contain just a few lines of code. I just want to show you how one can capture events in a handler and how the syntax differs from the SPS 2003 code. Following is the complete code for the handler:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Net.Mail;

namespace surveyhndlr
public class handler : SPItemEventReceiver
public override void ItemAdding(SPItemEventProperties properties)
SPList oSurvey = properties.OpenWeb().GetList("http://sp:81/SiteDirectory/site1/Lists/Survey2");
string userResponse =
oSurvey.Items[oSurvey.Items.Count - 1]["Is MOSS 2007 an excellent product?"].ToString();

string body = string.Empty;
if (userResponse == "Yes")
body = "Dear user, <BR> Thank you for voting in favor of MOSS 2007.";

body = "Dear user, <BR> Please install MOSS 2007 B2TR if you haven't already done so and then give it another try. B2TR will fix many issues that you are facing in Beta 2. ";

SmtpClient oSMTP = new SmtpClient();
oSMTP.Host = "mail.mysite.com";
share.point@yahoo.com","share.point@yahoo.com","Thanks for responding to the survey",body);


Don't forget to include "System.Net.Mail" namespace. This will be used in sending emails from the code. We are using ItemAdding event that will capture the user response before the response is actually submitted. Open your survey using the following line:
SPList oSurvey = properties.OpenWeb().GetList("http://sp:81/SiteDirectory/site1/Lists/Survey2");
The following line will return the user's response:
string userResponse =
oSurvey.Items[oSurvey.Items.Count - 1]["Is MOSS 2007 an excellent product?"].ToString();

It doesn't matter what the user response is. He can select "Yes" or "No". In both cases, an email will be sent to the user. We will just change the content of the mail, that's it!
Define an SMTP object.
SmtpClient oSMTP = new SmtpClient();
You can change your mail server using the following line:
oSMTP.Host = "mail.mysite.com";
Following line will send the mail.
oSMTP.Send("share.point@yahoo.com","share.point@yahoo.com","Thanks for responding to the survey",body);
I have hard coded the email addresses but you can get user's email address using the SPContext object. For example, you can use following code to get currently logged in user's email address:
SPContext ctx = new SPContext();
string useremail = ctx.Web.CurrentUser.Email;
7. Now, compile your code and strong name the assembly. Strong naming utility (sn.exe) can be found in the following folder:
C:Program FilesMicrosoft Visual Studio 8SDKv2.0Bin
Run the following command to strong name your assembly:
sn.exe -k key.snk
You can copy the sn.exe utility to the folder where your assembly is located. Resulting key will be written to the key.snk file.
8. Go to your project's properties (Right click project name in the solution explorer and select "Properties" from the menu) and select "Signing" from the menu that appears on the left. This will open a form.
Check "Sign the assembly" checkbox and choose the key file from the drop down (Click the "Browse..." button in the drop down to locate the key.snk file that you generated in the previous step).
9. Re-compile your assembly.
10. Place your assembly in the GAC. We will use ".NET Framework 2.0 Configuration" application, although there are other ways of adding the assembly to the GAC. You can use gacutil.exe tool as well. Anyway, Go to control panel, click "Administrative Tools" and select "Microsoft .NET Framework 2.0 Configuration".
11. Click "Manage the Assembly Cache" and then select "Add an Assembly to the Assembly Cache". Locate the assembly and click "Open".
12. Read the "Public Key Token" from the Assembly Cache. Select your newly added assembly in the assemblies list and note down the public key token that appears as the last column.
13. Your event handler has been placed in the GAC. Now it is the time to bind the event handler to the list. Unlike SPS 2003 where you could use interface to bind handlers, you will have to write few more lines of code because in MOSS 2007, you have to bind the event handlers programmatically. Create a new Windows Application in Visual Studio and paste following lines in the form's Load() event:

SPSite site = new SPSite("http://sp:81/SiteDirectory/site1");
SPWeb web = site.OpenWeb();
SPList survey = web.Lists["Survey2"];

string assemblyName = "surveyhndlr, Version=, Culture=neutral, PublicKeyToken=a34245adab33a20a";
string className = "surveyhndlr.handler";

survey.EventReceivers.Add(SPEventReceiverType.ItemAdding, assemblyName, className);
The public key token you noted down earlier will be used in this code. Define a variable named "assemblyName" of string type and include assembly's name, version, culture and publickeytoken. Define another variable called as "className" of string type and use the following line to add your handler to the EventReceivers list:
survey.EventReceivers.Add(SPEventReceiverType.ItemAdding, assemblyName, className);
14. That's all! Open the survey and respond to the question. Select "Yes" or "No", an email will be sent to the user, in this case, to you with a message specific to the user's response. You can do many things using event handlers. This is an excellent way of extending the "out of the box" functionality. In SPS 2003, you could use event handlers with document libraries only but in MOSS 2007, you can use event handlers with all lists. Users now have more power in their hands.

Friday, November 3, 2006

Creating a survey in MOSS 2007 programmatically

Creating a survey in MOSS 2007 programmatically
I wrote about surveys in one of my previous posts. You can read it here:
I showed you how you can create a survey in MOSS 2007. I demonstrated how you can use branching to skip specific questions and make your surveys meaningful. Today we will see how one can add a survey programmatically. It is very easy. Just a few lines in fact! Here is the code:
using Microsoft.SharePoint;
SPSite site = new SPSite("http://sp:81/SiteDirectory/site1");
SPWeb web = site.OpenWeb();
string surveyname = "Survey2";
SPListTemplate listTemplate = web.ListTemplates["Survey"];
System.Guid guid = web.Lists.Add(surveyname,"survey",listTemplate);
Note to Beginners: Don't forget to add reference to Microsoft.SharePoint.DLL. You will find this DLL in the following folder:
c:program filescommon filesmicrosoft sharedweb server extensions12isapi
The following line will add the new survey:
System.Guid guid = web.Lists.Add(surveyname,"survey",listTemplate);
First parameter is the survey's title, second parameter is description and the third is the template. This line will return a Guid. You can access a list by using either it's title or it's guid. Now that you have added a new survey in your site, you may also want to add users programmatically. There are two ways to add a new user. You can use obsolete methods. For example, have a look at the following lines:
SPList survey = web.Lists["survey2"]; //survey2 is survey's title
SPMember member = web.Users["sp\user1"]; //This user must exist in the parent site.
survey.Permissions.Add(member, SPRights.ManageLists);
This will add the user to the survey but here is what you will see on the screen:
The user has been added but when you view the user's permissions, you see a strange permission in the list. Permission is:
Auto-generated Permission Level 6asdf-4343-4235-f334-af342352355 - This permission level is automatically generated when the obsolete SPPermissionCollection class is used.
This happened because we used obsolete methods. Permissions.Add() is not supported any more. Similarly, SPRights.ManageLists is not supported. The new method of adding a user is to use SPRoleAssignment class. Here is how you do it:
SPRoleAssignment roleAssignment = new SPRoleAssignment("SP\user1", "user1@localhost", "User1", "Notes");
SPRoleDefinition RoleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
//Check inheritance
if (!survey.HasUniqueRoleAssignments)
MessageBox.Show("User successfully added!");
You can read more about SPRoleAssignment class on the following page:
Let's analyze the code:
SPRoleAssignment roleAssignment = new SPRoleAssignment("SP\user1", "user1@localhost", "User1", "Notes");
First parameter is user login, second is user email, third is user's name and last one is comments or notes.
SPRoleDefinition RoleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
We have selected "Contributor" role for the user. You can select any role from the following list:
1. Administrator
2. Contributor
3. Guest
4. None
5. Reader
6. WebDesigner
Add role definition binding:
You must use following lines to check inheritance from the parent site:
if (!survey.HasUniqueRoleAssignments)

Check if user is inheriting permissions from the parent site. You can check this with "HasUniqueRoleAssignments" property. [Reference: http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.splist.hasuniqueroleassignments.aspx]
Use "BreakRoleInheritance()" method to assign permissions to the user. This method accepts a boolean value. If you pass "True", role assignments will be copied from the parent site and if you pass "False", then you can assign new permissions. [Reference: http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.splist.breakroleinheritance.aspx]
If you don't use this check, you won't get an error when you run the code for the first time but second time, you will get a run time error. So, it is better to use the check to avoid any runtime errors.
Here are the final lines:
survey.RoleAssignments.Add(roleAssignment); //Add roleAssignment
survey.Update(); //Apply update
MessageBox.Show("User successfully added!"); //Display a success message
You can download application (source code) in RAR format from the following location:
Open your site and view newly added survey and user.
1. Open site and click on the newly added survey (under Site Hierarchy).
2. Click "Settings > Survey Settings" to open settings page.
3. Click "Permissions for this survey" link to open the permissions page.
4. You will find your newly added user along with his permissions on this page.
Please feel free to send your comments and suggestions at share.point@yahoo.com

Thank you.


Wednesday, November 1, 2006

Upload tool for MOSS 2007

I created this tool for MOSS 2007. It was the time when first beta was released. There was so much craze for this product. People were busy exploring the product. I wrote this application for demo and my readers really liked this small tool although it was meant for demo only. I lost this post along with hundreds of other posts when this blog server crashed a few months ago and yesterday I was talking to an old blog reader who told me he still had this post. I took the code from him and I am reposting it. I know this application is not in demand any more but it's still a good application for learning object model programming.

upload tool

Download this application here.

Creating a Survey in MOSS 2007

Creating a Survey in MOSS 2007

You may have created surveys in SPS 2003. Surveys are also available in MOSS 2007 and the best new feature is "Branching". You can skip to a specific question based on the user response. This helps a lot in creating *intelligent* surveys. Another new feature is workflow. Now, you can enable workflow in your surveys. Let's create a survey and see how branching works:
1. Open a site.
2. Click on "Surveys" in Document Center. This will open the following page. Any surveys already created in your site are available on this page. Click the "Create"  button to go to the web part selection page.
3. The following page will open when you click the "Create" button (see figure in step 2). Select "Survey" in Tracking Section.
4. In the new page that opens, give a name to your survey, add some meaningful description. There are a couple of other options that you can select, for example, select "Yes" if you want to show user names in survey results or select "Yes" if you want to allow multiple responses by a single user. Click "Next" to go next screen.
5. Here you can define your questions. For demo purposes, I added the following as my first question:
Does MOSS 2007 contain useful features?
Enter "Yes" and "No" on separate lines as shown below. The type you selected for this question was "Choice". These options should be displayed as radio buttons. You can show them in drop down as well. It doesn't make any difference.
Click "Next Question" to add another question. Next question is:
Which features do you like best?
Options are: (Radio buttons)
a. Document Libraries
b. Workflow
c. Custom Lists
Click "Next Question" to add following question:
Your comments about built-in workflow? (Multiline text  box)
Click "Next Question" to add following question:
Why do you think that MOSS 2007 doesn't contain useful features? (Multiline text box)
Click "Finish". Next, you will see the following page:
6. Click on "Permissions for this survey". You will see following screen. Click users here and assign permissions. Click "Add Users" (Action link) to add users.
Assign "Approval" rights if you intend to use workflow.
7. Click "Settings > Survey Settings" to change settings.
8. Click "Advanced Settings".
9. Make sure following options are selected (see figure shown below):
a. All responses
b. Only their own.
10. On the settings page, click the first question to add branching.
In the branching section (bottom of the page), you will notice their are two drop downs, one against "Yes" which is your first option in question 1 and the second against "No" which is your second option in question 1. In "Yes", select "Which features do you like best" and in "No", select "Why do you think that MOSS 2007 doesn't contain useful features?". Click OK.
Now click on second question in the list. Second question should be "Which features do you like best?". You will see that there are three options available in the branching section: Document libraries, workflow, custom lists. Against all three options, select "Your comments about built-in workflow?".
Click on question 3 which should be "Why do you think that MOSS 2007 doesn't contain useful features?". In branching section, select "Your comments about builtin workflow?" against the "Any Response".
Your branching is complete. Run your survey to test branching options.

11. You can also change the order of the questions.
Depending on the option selected by the user in question 1, second question will be shown accordingly.