Today i'm giving a presentation for a group of students about a project using SharePoint. In my case its a project built in Windows SharePoint Services (WSS).
Last week i was at the customers location and did a backup of the WSS site. Today i tried to set it up in my Virtual PC environment, and with success! :)
There are still some issues which are not handled by the backup / restore functionality of stsadm command.
Just for your information some of these issues:
- It is only possible to restore the WSS site when the same or higher service pack is installed
- If you're using Custom WebParts. You have to copy them into your bin folder or install them into the GAC.
- Also do not forget to place the <SafeControl> entry in the web.config file
- If you're using SessionState do not forget to turn it on in the web.config file
- I always advise to create per site your own layouts and images folder. Change the paths of the virtual directories in IIS
I used the following command line to restore the database:
stsadm -o -restore -url http://somsite -filename d:\pub\somesite.bkp -overwrite
Its always a fact that Microsoft does not support modifications to database schemas or database structures of SharePoint. These changes can be overwritten by service packs, upgrades or new versions of the product.
But.... still.... i came accross an article by Andy May which contained a link to the MSDN of microsoft where Microsoft describes each table of the SharePoint database. It still contains a Microsoft standard warning at the top. :)
So, whats the reason for this? Why listing the database tables?
The link to MSDN can be found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/tsdbTables_SV01051532.asp
The article of Andy May can be found at:
http://www.sharepointblogs.com/andymay/archive/2005/10/25/4025.aspx
I always like these kind of postings. Proofing that some things are possible :) In his example he adds a WebPart Page to a Document Library by altering some code in the well-known ONET.XML. Do not be afraid of editing this file. Its quite easy to understand whats going on.
Check your documentation "Microsoft SharePoint Products and Technologies 2003 Software Development Kit" (file spptsdk.chm) and look for ONET.XML. You will find an article describing each bit of this file.
The article describing pre-populating a document library can be found at:
http://blogs.msdn.com/cjwalker/archive/2005/10/26/484879.aspx
Thanks to Christopher Walker!
Todd wrote a nice article about showing styles when moving your cursor around. A lot of people asked him how to alter elements of WSS WebPart Pages. He gives a good walk-through and some code. Thanks Todd :)
http://mindsharpblogs.com/todd/archive/2005/10/25/798.aspx
I found a nice topic in the SharePoint documentation which explains the properties that can be set on the command line using the stsadmin.exe tool with the getproperty and setproperty operations. This is as follow:
stsadm.exe -o getproperty -pn <property name> [-url <url>]
stsadm.exe -o setproperty -pn <property name> -pv <property value> [-url <url>]
As stated in the "Microsoft Office SharePoint Portal Server 2003 Administrator's Guide" (file SharepointPSAdmin.chm):
"Some properties are available for the entire server, and are called server properties. Some are only available for an individual virtual server. When you get or set a server property, you can omit the url parameter. You must include the url parameter to get or set virtual server properties. For more information about setting properties, see "Introducing the Administration Tools for Windows SharePoint Services" in the Windows SharePoint Services Administrator's Guide."
The properties are divided in several categories:
Server Properties for Windows SharePoint Services
- Antivirus properties
- Data retrieval services properties
- HTML Viewer properties
- Site confirmation and automatic deletion properties
- Usage analysis properties
Virtual Server Properties for Windows SharePoint Services
- Alert properties
- Content database properties
- Data retrieval services properties
- General properties
- Site confirmation and automatic deletion properties
Lookup "Command-Line Properties" in the mentioned file for the complete list and explaination of each property divided over the categories.
But it would be nice if you can access these properties programmatically. This is possible with the following code:
Microsoft.SharePoint.Administration.SPGlobalAdmin globAdmin = new Microsoft.SharePoint.Administration.SPGlobalAdmin();
Microsoft.SharePoint.Administration.SPGlobalConfig globConfig = globAdmin.Config;
SPPropertyBag propBag = globConfig.Properties;
System.Collections.ICollection keys = propBag.Keys;
foreach (object key in keys)
{
output.Write(SPEncode.HtmlEncode(key.ToString()) + " :: " +
SPEncode.HtmlEncode(propBag[key.ToString()]) + "<BR>");
}
Did you ever wonder where those sites went if you create one under the Sites directory within SharePoint Portal Server? I did! If you try to list a sites by using the SPSite.AllWebs they will not show up. Why? So far as I can see they are created as "floating" sites. But there is a way to list them. The Sites directory is a Area and can be found easily.
First create a TopologyManager and retrieve the PortalSite object by using an Uri object.
TopologyManager topologyManager = new TopologyManager();
Uri uri = new Uri("http://localhost/");
PortalSiteCollection sites = topologyManager.PortalSites;
PortalSite portalSite = sites[uri];
Then get the PortalContext and use this to get the Guid of the SystemArea. The SystemArea is an enumeration providing you some starting points of Areas.
PortalContext portalContext = PortalApplication.GetContext(portalSite);
Guid homeGuid = AreaManager.GetSystemAreaGuid(portalContext, SystemArea.Home);
Based on the Guid its very easy to retrieve the actual Area object. And based on that Area object we retrieve the Sites Area object from its children.
Area homeArea = AreaManager.GetArea(portalContext, homeGuid);
Area sitesArea = homeArea.Areas["Sites"];
Loop through the AreaListings in this Area object and check if its type is ListingType.Site. The URL property contains the url to the created sites.
foreach(AreaListing listing in sitesArea.Listings)
{
if (listing.Type == ListingType.Site)
{
output.WriteLine(String.Format("{0} ({1})<br>", listing.Title, listing.URL));
}
}
I got a lot of questions of colleages regarding custom templates and site definitions.
As stated in the help: "A custom template is a customization applied to a site definition. When a user customizes a site or list in the user interface, the custom template consists of the difference between the original state of the site or list as determined by its definition and the state of the site when the custom template is generated. Custom templates remain tied to a particular site definition (for example, the one for a SharePoint site or a Meeting Workspace site), so that if the site definition is not present or is changed, the custom template will not work."
In many cases building Portals with SharePoint Portal Server you want to change the defined Site definitions. These Site definitions are the templates you can choose from when you create a new site.
The problem with changing a Site definition is that when somebody else in another Portal creates a site with the same template, he is also getting your changes. So the following sequence of steps can be taken to create your own Site definition.
The first thing you have todo is copy an existing Site definition and rename it. Existing site definitions are found in the folder <localdrive>:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\<localeid>. For example copy the STS folder and rename it to MYSTS.
In this folder you will find an XML folder containing the file ONET.XML. This is the schema file containing Collaborative Application Markup Language (CAML). If you want to make changes to the listings, WebParts and other stuff showing up when creating a site, this is file to make the changes in.
The next step is telling SharePoint that there is a new template defined. Under the folder <localdrive>:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\<localid>\XML you will find a schema file called WEBTEMP.XML. Copy this file and call it WEBTEMPMY.XML. It is very important that the name of the file starts with WEBTEMP.
Your WEBTEMPMY.XML will look like this:
<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="11.0" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
<Template Name="MYSTS" ID="10200">
<Configuration ID="0" Hidden="False" Title="<some title>" Type="0" ImageUrl="<someimage>" Description="<somedescription>">
</Configuration>
</Template>
</Templates>
The following things are very important:
- Make sure that the Name property of the Template element is the same as the name of your folder.
- The ID property of the Template element should be in the range of 10000 or higher. Make sure its not used anywhere else.
- The ID property of the Configuration element points to a configuration with the same id in the ONET.XML.
- Property Hidden determines if the template should appear in the list when creating sites. It could be that you create your own sites based on the Site definition in a custom WebPart and users are not able to use your Site definition.
The final step is resetting the IIS by calling iisreset. It also works when recycling the application pool used by your Portal.
Further information regarding this subject can be found in the article "Creating a Site Definition from an Existing Site Definition" in Microsoft SharePoint Products and Technologies 2003 Software Development Kit.