Archive

Archive for the ‘Sharepoint’ Category

SharePoint Upgrade Issue

January 7th, 2010

I have faced a weired issue while upgrading SharePoint Server 2007 to SP1 on one of our development servers. Whenever I executed WSS and MOSS upgrade installer, it gives me error “detection failed, this could be due to corrupted installation”. I tried following to overcome the issue but none of them actually worked:

  • WSS SP1 wizard failed
  • KB941422 execution failed
  • Force upgrade with psconfig command line “psconfig -cmd upgrade -force” failed
  • “stsadm -o upgrade -forceupgrade -inplace” also failed
  • Disintegrated server from farm but it still failed

Read more…

admin Sharepoint , , , , , ,

SharePoint – Deletion In Batches

December 16th, 2009

I have been facing an issue after inserting quite much data for testing into one of my lists. It was really hard to get rid of the data and the deletion in sequence was just a nightmare. After some googling I figured out batch deletion would be a perfect solution. Sample code is shown in the following:

Batch Deletion Code

As my data was huge in size like 100,000+ records were there. I prepared batches of thousands and deleted one batch at a time. During each batch, I applied a sleep as well. This way deletion was so fast that I was able to delete all records in like less than an hour.

admin Sharepoint , , , , , , ,

SharePoint Template, Theme and Site Definition

December 3rd, 2009

If you have been reading stuff about sharepoint, you must have read/listened these three terms invariably. Yeah template, theme and site definition. All these three are different, lets talk about each one of these:

Themes

Difficulty level for this entity is lower. This is a collection of stylesheets and images to help creating a skin for the site. It’s all about the look and feel of your site. There are several style sheets already available in “TEMPLATE\LAYOUTS\1033\STYLES” folder.  But it is not recommended to modify these directly as it will effect other sites as well. Themes are available under “TEMPLATE\Themes” folder.

Read more…

admin Sharepoint , , , , , , , , ,

Sharepoint Load Test

November 3rd, 2009

I had to pass through a scenario that may rare as far as working with MOSS is concerned, sharing it on my blog so it might help someone else. I had built an office automation application using MOSS. We need to pull legacy data within our application as well. In the application there were several sharepoint views.

Problem

After performing import for the legacy data, the total count of items was like more than 150k. I see the following problem opening up page in designer:

Issue with SPD

Read more…

admin Sharepoint , , , , , , , , ,

Form Based Authentication

April 15th, 2009

While configuring sharepoint server 2007 for form based authentication, I have came across a lot of issues. One site that was really helpful while configuring was:

http://www.codeproject.com/KB/sharepoint/FBA.aspx

After going through all the steps, whenever I try to access the site that was configured for form based authentication. The page just refereshes to itself and do not produce any errors. I read through a lot of blog items to find the result but none of them worked for me. 

While trying different options, I came to know that the user provider database which contains all form users should have a windows local account in order to access the users. Once I had configured that, the login page started functioning

:)

admin Sharepoint , , , , ,

Feature Installation & Activation

October 8th, 2008

Problem

We have discussed automated deployment in another post, now let’s discuss how we can install a feature. Doing an automated feature installation contains some problems if we use SDK. For these problems, please keep on reading.

Solution

The following code snippet should install a feature on the form.

SPWebApplication app = SPWebApplication.Lookup(new Uri(DefaultZone));
SPFeatureDefinitionCollection col = farm.FeatureDefinitions;
SPFeatureDefinition def = col.Add(featurefile, id, true);
app.Features.Add(id, true);

The above code installs the feature but it do not activate the feature even if we try to activate it. The activation step needs to be performed manually.

If we wanted to somehow perform this step, we can do it using the following code (this does not use the SDK):

ProcessStartInfo pStartInfo = new ProcessStartInfo();
//specify gacutil.exe whith which to start the process
pStartInfo.FileName = @”.\stsadm.exe”;
pStartInfo.Arguments = string.Format(“-o installfeature -filename {0} -force”, featureName);
pStartInfo.UseShellExecute = false;
pStartInfo.CreateNoWindow = true;
pStartInfo.WindowStyle = ProcessWindowStyle.Hidden;


//start the process
Process process = Process.Start(pStartInfo);


//wait till the process completes
process.WaitForExit();

The above code will install the feature on the farm where this code is being executed. If we wanted to activate it as well, we can write down the same statements with activatefeature switch.

admin Sharepoint , , , , , , ,

Automated Deployment for Complete Website

September 29th, 2008

As I’ve discussed different deployment options available in MOSS 2007. In this post, I will discuss how we may write down script for deploying complete website. First of all, create a project in Visual Studio 2005 and add references for Microsoft.Office.Sharepoint & Microsoft.Office.Sharepoint.Services. We will step by step look at scripts for achieving different targets. We will need to write scripts for the following steps:

- Create Web Application (along with site collection)
- Restore our website to newly created site
- Add features as required

Create Web Application

In order to create a web application, you need to write down the following code. The following code will create a new web application with a site collection within it.

// web site port
int port = Port_No;


// web site root directory
string rootDir = PATH; // it should be the path to the web app within VirtualDirectories folder


// web application name
string webAppName = Name_Of_The_Application; // this could be any string


// app pool username
string appPoolUser = User_Name; // name of the user who has rights over central administration

// build the password as a secure string
SecureString appPoolPwd = new SecureString();
foreach (char i in txtPassword.Text)
{
appPoolPwd.AppendChar(i);
}


appPoolPwd.MakeReadOnly();


Uri defaultZone = new Uri(Default_Zone);
Uri intranetZone = new Uri(Intranet_Zone);

// the database server that will host the content database(s) for this web application
string dbServer = DB_Server;

// the name of the first content database for this web application
string contentDb = Content_DB_Name; // name of the content db that will be created

// for the top-level site
string url = “/”;

// the site title
string siteTitle = Site_Title;

// the site description
string siteDesc = Site_Desc;

// this is the MS language Locale ID. see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
uint LCID = 1033;

// this is the site template for the Publishing Site – Collaboration Portal merged site definition
string template = “SPSPORTAL”; // you may change it to any other template you want

// first site owner login name
string ownerLogin = Site_Owner; // this should be a user name from active directory

// site user name
string ownerName = User_Name; // this could be any descriptive name you want to give

// site owner email
string ownerEmail = Email_Address;

// get an instance of the farm from the administrative service
SPFarm farm = SPWebService.AdministrationService.Farm;

// use the SPWebApplicationBuilder to create web application and pass the local farm instance to the builder class
SPWebApplicationBuilder webAppBld = new SPWebApplicationBuilder(farm);


// assign a GUID to the IIS web application.
try
{
webAppBld.Id = System.Guid.NewGuid();
}
catch (Exception ex)
{

}

// the web application’s port
webAppBld.Port = Port;

// create a root directory for the IIS application using the SYSTEM.IO namespace
DirectoryInfo rootDirInfo = new DirectoryInfo(rootDir);

// create the root directory and assign it to the web app.
webAppBld.RootDirectory = rootDirInfo;

// set the ID of the web application pool this is not a GUID as the WSS SDK suggests
webAppBld.ApplicationPoolId = webAppName + ” Pool – ” + port.ToString();

// uses the IdentityType enumeration. This can be one of four values but for SharePoint web farms is usually a specific user account in the domain.
webAppBld.IdentityType = IdentityType.SpecificUser;

// be sure that this user exists and that the password matches the value stored in the SecureString
// appPoolPwd value.
webAppBld.ApplicationPoolUsername = appPoolUser;

// assign the secure string value as the app pool password
webAppBld.ApplicationPoolPassword = appPoolPwd;

// the default is false so that Kerberos auth. is supported. If  you’re not using Kerberos, set this to true
webAppBld.UseNTLMExclusively = true;

// default is false
webAppBld.AllowAnonymousAccess = false;

// the default is false so that SSL is not used in IIS. set this to true if the IIS web site hosting this web application should use SSL
webAppBld.UseSecureSocketsLayer = false;

// Set the default zone that appears in Alternate Access Mappings
// will probably want to change this to the URL value that most users select for browsing this web application
webAppBld.DefaultZoneUri = defaultZone;

// this will create a new content data (default is true)
webAppBld.CreateNewDatabase = true;

// set the database server that will host the database
webAppBld.DatabaseServer = dbServer;

// create a new content database for the web application
// be sure this is unique. Consider appending a GUID onto
// the end of the database name as Microsoft does when you
// use Central Admin. to create a web application
webAppBld.DatabaseName = contentDb;

// set the database username to null or an empty string
// to use Windows integrated authentication. Set both
// the username and the DatabasePassword password property
// if you want to use SQL auth.
webAppBld.DatabaseUsername = String.Empty;


//// get the server hosting the search service
SPSearchServiceInstance ssi = null;


foreach (SPServiceInstance sp in SPServer.Local.ServiceInstances)
{
if (sp.GetType().IsAssignableFrom(typeof(SPSearchServiceInstance)))
{
ssi = (SPSearchServiceInstance)sp;
break;
}


}


try
{
webAppBld.SearchServiceInstance = ssi;
}
catch (InvalidCastException ex)
{
}

// assign a comment to the web application to create
// if not set, this will default to SharePoint – <port>
webAppBld.ServerComment = webAppName + ” – ” + port.ToString();

// mention that this can take a long time
Console.WriteLine(“Web app. creation has started.”);
Console.WriteLine(“This operation an take as long as 15 minutes in our tests.”);

// create the new web application
SPWebApplication webApp = null;
try
{
webApp = webAppBld.Create();
}
catch (Exception ex)
{
}
Console.WriteLine(“Web Application created.”);

// specify time zone. You can either enumerate the GlobalTimeZones
// collection to find the right timezone or look it up on the
// Central Administration – Application Management – Web Application
// General Settings page.
webApp.DefaultTimeZone = SPRegionalSettings.GlobalTimeZones[14].ID;

// size in megabytes
webApp.MaximumFileSize = 75;

// enable alerts
webApp.AlertsEnabled = true;

webApp.Name = webAppName + ” – ” + port.ToString();

Console.WriteLine(“Updating and provisioning the web application.”);

try
{

// update the web app with the settings specified
webApp.Update();

// provisions the web application in IIS and creates the content
// database if one was specified
webApp.Provision();
}
catch (Exception ex)
{
}


Console.WriteLine(“Updating and provisioning the web application complete.”);

// perform an IIS reset operation iisreset /noforce if you’re in a web farm
Console.WriteLine(“Creating the top-level site collection.”);
Console.WriteLine(“This can also be a long running operation.”);


try
{

// create a site collection with an out of the box site definition
SPSite SiteCollection = webApp.Sites.Add(url, siteTitle, siteDesc, LCID, template, ownerLogin, ownerName, ownerEmail);

// close the site collection
SiteCollection.Close();
}
catch (Exception ex)
{
}


Console.WriteLine(“Top level site collection creation complete.”);

Restore Website

In order to restore website, write the following lines of code:

SPWebApplication app = SPWebApplication.Lookup(new Uri(Default_Zone));
SPSiteCollection clt = app.Sites;
clt.Restore(Default_Zone, @”.\YourBackup.bak”, true);

The above three (3) statements would restore your website to the newly created web appliation.

admin Sharepoint , , , , ,

Deployment Basics

September 17th, 2008

Deployment is a very vast topic when it comes to MOSS. If you are good to go with .Net application deployments, you should know that it really sucks on sharepoint as it is not an easy trade.  Consider the following scenarios:

  • You have developed a web application using sharepoint. You have a requirement to deploy your web application with all the site contents as well as data.
  • You have already deployed the web application and you would like to provide your client with a patch to be executed on their MOSS website to get the latest site contents. At the same time, the data should not be disturbed on the production environment.
  • You have come up with a requirement to install lists, web parts, custom pages and features on the production server. You want it done through automation. I will explain it in a separate post.

Lets look at these scenarios one by one:

Deploying Complete Website

In order to deploy complete website, we use backup/restore method. It restores all site contents and any data to the destination server. Though there are certain limitations:

  • It do not restore any assemblies that you have placed in your \bin folder under VirtualDirectories folder.
  • It did not include features.
  • There could be even more limitations as you face them.

I prefer the backup/restore of stsadm utility that can be achieved by simply writing down following commands:

stsadm -o backup -url http://server_name:port -filename \\anylocation\backup.bak

We may restore this backup.bak file to any server farm using the following command:

stsadm -o restore -url http://server_name:port -filename \\anylocation\backup.bak

The above method to take backup of the site produces one bak file as you can see in the statement backup.bak. There is another way you may use Central Administration backup method, go to Operations tab and follow “Perform a backup” link. This backup produces a number of files. The same backup may also be taken using the command line by following the following commands:

stsadm -o backup -directory \\backup -backupmethod full -item portNo

The above command takes a full backup of the given port number and produces same set of files as being produced by central administration. \\backup means a backup shared folder.

In order to restore from the backup produced by the above command, follow this syntax:

stsadm -o restore -directory \\backup -restoremethod overwrite -suppressprompt -item portNo

Deploying Contents

If you would like to deploy only site contents to the production server, the best possible way is using import/export feature.  Again using stsadm utility, the following commands do the trick:

stsadm -o export -url http://servername:port -filename \\location\exported_data.cmp

The same command is being used to import site contents to production server:

stsadm -o import -url http://servername:port -filename \\location\exported_data.cmp

However, note down that features must be de-activated before you execute the import command on the destination server. Otherwise, you will experience different errors while importing.

admin Sharepoint , , , , ,

Modify the View Sorting Order

September 14th, 2008

After creating a list, we may create views on it. Different views give us the desired look and feel we want. You may encounter a problem as listed below:

Problem

You click on your list and select a view to open up. You edit an item and when you return back either by clicking OK or Cancel, you will be navigated to a default view instead of the view you were in. This issue arises primarily when you access your sharepoint site out of the network i.e., through internet.

Solution

The solution is that you modify the sorting order of views in the drop down list. In order for that, you need to select your view as default view. By doing so, your view will be listed first in the drop down. The order will be modified.

In order to make your view default, goto Site Settings, then select your list and click on your view that you wanted to mark as default. In your view, you will see a checkbox saying “select this view as default”. Check that option and you are done.

warfi Sharepoint , , , , , , ,

Working with Ajax on MOSS 2007

September 11th, 2008

Working on ajax sucks at times even now. Now means using SP1 for MOSS 2007. For instance, if you develop a custom page and using the update panel for asp.net calendar control will not produce partial page post backs. I have came across this issue and spent a lot of time figuring out the issues. Finally, the following seems to make everything work for me. Try your luck :)

Working on ajax sucks at times even now means even with SP1 of MOSS 2007. Facing issues with some of the controls not producing partial page postbacks will take you to this MS knowledge base:

Microsoft Knowledge Base Article

The above knowledge base may help you a little bit, it is regarding creating updatepanel and controls dynamically meaning programatically instead of going for design time controls.

Apart from above solution, the following is a solution that really works. If you have put your controls in update panel and partial page postbacks are not working for some of the controls specially for controls like link button. The following solution surely works.

Follow these steps to make it work:

Step 1

Modify web.config <authorizedTypes> section to include all related assmebly references, so that it looks similar to that:

<authorizedTypes>
<authorizedType Assembly=”System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35? Namespace=”System.Workflow.*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35? Namespace=”System.Workflow.*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35? Namespace=”System.Workflow.*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowActivationProperties” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowTaskProperties” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowHistoryEventType” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.WorkflowActions” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35? Namespace=”System.Workflow.*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35? Namespace=”System.Workflow.*” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowActivationProperties” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowTaskProperties” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.Workflow” TypeName=”SPWorkflowHistoryEventType” Authorized=”True” />
<authorizedType Assembly=”Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” Namespace=”Microsoft.SharePoint.WorkflowActions” TypeName=”*” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”Guid” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”DateTime” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”Boolean” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”Double” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”String” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Collections” TypeName=”Hashtable” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Collections” TypeName=”ArrayList” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Diagnostics” TypeName=”DebuggableAttribute” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Runtime.CompilerServices” TypeName=”CompilationRelaxationsAttribute” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Runtime.CompilerServices” TypeName=”RuntimeCompatibilityAttribute” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”Int32? Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System” TypeName=”TimeSpan” Authorized=”True” />
<authorizedType Assembly=”mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089? Namespace=”System.Collections.ObjectModel” TypeName=”Collection`1? Authorized=”True” />
</authorizedTypes>

Step 2

You will need to modify the master page, edit master page using Sharepoint designer. A javascript method will be called on onload. You need to remove this call so that your body tag looks like:

<body>

instead of:

<body onload=”javascript:if (typeof(_spBodyOnLoadWrapper) != ‘undefined’) _spBodyOnLoadWrapper();”>

Step 3

We will need to modify javascript method _spFormOnSubmitWrapper() which is called on Form post in your master page, this method is found in init.js file. init.js file is  installed with MOSS 2007 on server. The file is located at: Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033.

Open the file and go to method _spFormOnSubmitWrapper(), the following code will be found in the file:

if (_spSuppressFormOnSubmitWrapper)
{
return true;
}
if (_spFormOnSubmitCalled)
{
return false;
}

Replace the above code with the following code:

if (_spSuppressFormOnSubmitWrapper)
{
return true;
}
if (_spFormOnSubmitCalled)
{

}

Note that “return false” statement has been commented out. This will make ajax calls to work properly. This line is commented out because if the page is already posted back, sharepoint does not post it back again. For ajax to work properly, it is required to disable it so that partial postbacks work for every server call.

admin Sharepoint , , , , , , ,


Copyright © 2008-2009 W@rfi