Archive

Archive for the ‘SharePoint’ Category

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.

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.

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.

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.

SharePoint , , , , , , ,

Accessing Sharepoint site on Internet

September 9th, 2008

If you are planning to access your sharepoint website on internet, you will be posed with different problems. I will address all of these problems.

Problem 1:

You wanted to access your sharepoint site on internet.

Solution

Just go to Operations -> Alternate Access Mapping link. Click on “Edit Public URLs”. You will see a GUI similar to the following:

alternate access mapping

Select your we abbplication and provide a url for internet, for this url you will need to write a rule in ISA Server. Once it is done, you will be able to access your sharepoint site on internet.

Problem 2

You have accessed your sharepoint site on internet successfully but you will face a problem that whenever you access your second level or third level links, you will get “Page cannot be displayed” error.

Solution

  • If you are using ISA Server 2004, edit your rule. Edit HTTP of the Rule and unmark “Verify Normalization” option.
  • If you are using ISA Server 2006 in order to define a rule, define a rule for “sharepoint website” instead of “website”. It will automatically unmark “Verify Normalization” option.

Problem 3

You have successfully accessed all your pages on the internet. But still you may face an issue if you have developed a custom page to be opened on clicking “New Item” on a list. The custom page will open as required on intranet but when accessed through internet, you will see the default sharepoint “new form” instead of your custom form.

Solution

In order to solve this issue, again go to Alternate Access Mapping and go to “Edit Public URLs”. In the Intranet box, remove the port number like if http://server_name:port was written, make it http://server_name with no port number. Now when you will access your site on internet, you will be able to see your custom form as required. This solution is true if you are using ISA Server 2006. For earlier versions, this solution won’t work.

SharePoint , , , , , ,


Copyright © 2006-2011 W@rfi