Thursday, March 28, 2013

Default viewnot pointing to AllItems.aspx

Issue:
The landing page  for "Site Pages"/"Pages" library will not be AllItems.aspx. Even if we change the library settings for default view, the change is not committed.

Solution:
In such cases, run the following PowerShell script.

$site = Get-SPSite "http://SITEURL"
$web=$site.OpenWeb()
$list = $web.Lists["Site Pages"]
$rootfolder = $list.RootFolder
$rootfolder.WelcomePage = "Forms/AllPages.aspx"
$rootfolder.Update()
Write-Host $list.RootFolder.WelcomePage
$web.Dispose()

 

Get list of corrupted files from SP Content Database

Issue:
When we try to download a file from SharePoint site, it might take us to error page. We can find the following error in the ULS log:

Background file fill operation caught exception: System.InvalidOperationException: Operation is not valid due to the current state of the object.     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundSqlFileFiller.OnReadComplete(IAsyncResult result) 

System.InvalidOperationException: Operation is not valid due to the current state of the object.    at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundFileFiller.Fill()     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBuffer.WaitForIntervalFill(SPInterval i)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedMemoryStream.Read(Byte[] array, Int32 offset, Int32 count)     at Microsoft.SharePoint.SPFileStream.Read(Byte[] buffer, Int32 offset, Int32 count)     at Microsoft.SharePoint.ApplicationPages.Download.WriteStrmToResponse(Stream strm)     at Microsoft.SharePoint.ApplicationPages.Download.WriteFile(String sourceUrl)     at System.Web.UI.Control.LoadRecursive() 

Cause:
The SharePoint content database is having corrupted files.

Solution/Work around:
Run the following query against a content database in SharePoint 2010 (and above) to get the list of corrupted  files:

select * from AllDocs with(nolock) where id in ( select distinct (id) from AllDocStreams with(nolock) where Content =0x )
 
Delete the file(s) and reupload the files. There is no direct way to fix the corruption in the database.

Thursday, October 8, 2009

Understanding out MOSS Template Directory

The core of all sharepoint operations for for the farm lies in [Disk Drive]\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE. All sharepoint customizations need to go through modifying or adding files in this directory. Let me explain what each directory does and what the files under the directory are ment for.

The TEMPLATE\1033 Directory :

There are two directories that you need to know about here. The Workflow directory is where you will find the WSS.ACTIONS file. This file is used by SharePoint Designer 2007’s Workflow Designer. All of the workflows functions available to Designer are defined here. If you create workflow functionality using Visual Studio 2005/2008 and you want the functions to appear within the Workflow Designer, you will need to create a new .ACTIONS file.
The TEMPLATE\1033\STS Directory :

The SharePoint Team Services or STS directory has one sub-directory within it. The DOCLIB directory contains several further sub-directories, each of which holds a template for a specific content type. There are templates for the Office applications, Word, Excel, PowerPoint and OneNote. There are also templates for the different types of page that can be created in SharePoint.
The TEMPLATE\1033\XML Directory :

A more important directory within 1033 is the XML directory. Within this directory are several XML files.
Note : Changes to any of the file could be overwritten by SharePoint Service Packs.
DEADWEB.XML – This file is used during the site expiration process. Only change this file if you need to change the message that is displayed during the site expiration process.

RGNLSTNG.XML – This file holds the regional settings used by SharePoint 2007. You should not need to change this XML file.WEBTEMP.XML – This file defines the pointers to the GLOBAL, STS, MPS, CENTRALADMIN, WIKI and BLOG site definitions. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).
WEBTEMPBDR.en-US.XML – This file defines the pointers to the BDR site definition. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).
WEBTEMPOFFILE.XML - This file defines the pointers to the OFFILE site definition. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).

WEBTEMPOSRV.XML - This file defines the pointers to the OSRV site definition. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).

WEBTEMPSPS.XML - This file defines the pointers to the SPS, SPSPERS, SPSMSITE, SPSTOC, SPSTOPICM, SPSNEWS, CMSPUBLISHING, BLANKINTERNET, SPSNHOME, SPSSITES, SPSCOMMU, SPSPORTAL, SRCHCEN, PROFILES, BLANKINTERNETCONTAINER and SPSMSITEHOST site definitions. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).

WEBTEMPSRCH.XML - This file defines the pointers to the SRCHCENTERLITE site definition. You can amend this file to either display or hide site templates during the New Site Creation process (newsbweb.aspx and scsignup.aspx).It is preferable to clone and existing site definition and associated

WEBTEMPxxx.XML : file rather than edit an existing one. This will prevent your changes from being overwritten if a Service Pack is applied.The final directory under 1033 is STS. This directory holds a subdirectory, DOCTEMP which contains further subdirectories that hold the definitions and templates for document types that are associated with document libraries. You will find templates for Microsoft Word, Excel and PowerPoint amongst others. You should not need to amend any of these files.

TEMPLATE\ADMIN Directory :

The files in the ADMIN directory are used by the Central Administration pages. There are three directories within ADMIN; 1033, Content Deployment and SSO. 1033\Policy\Report contains a reporting template and sample data. The Content Deployment directory contains the DeploymentUpload.aspx page. Finally, SSO contains all of the aspx pages for Single Service Sign-On. These files should not be amended.
The TEMPLATE\CONTROLTEMPLATES Directory :

The CONTROLTEMPLATES directory is where the ASP.NET 2.0 control template files are held. Control templates are small re-usable files that contain components of a web page. An example is welcome.ascx. The welcome.ascx file defines the dropdown menu that appears under Welcome name on the top navigation section of a SharePoint 2007 page.These pages are pulled into SharePoint 2007 aspx pages. You can create your own ascx pages.
The TEMPLATE\DocumentTemplates Directory :

This directory contains one file, wkpstd.aspx, which is the base master file for Wiki pages.Tips & Tricks : It is worth noting that although this page can be cloned and modified it will not be used by any Wiki page other than the first page that is created. This is because the wkpstd.aspx page is hard coded and is always used to create further Wiki pages.
The TEMPLATE\FEATURES Directory :

The FEATURES directory holds subdirectories for each Feature that is available within SharePoint 2007. Each of these subdirectories will hold at least one file, feature.xml – this file will define the Feature and will have pointers to any other files required by the Feature.
The TEMPLATE\GLOBAL Directory :

The GLOBAL directory holds two very important files; default.master and mwsdefault.master.The default.master file is the master file that all files are based on. If you change this file, the change will be applied to every page that was created using an out-of-the-box site definition.
The mwsdefault.master file is the master file that all Meeting Workspace files are based on. If you change this file, the change will be applied to every Meeting Workspace page that was created using an out-of-the-box site definition.
The GLOBAL\XML directory holds the master ONET.XML file and master view XML files.You should not need to modify any of the files within the Lists or XML directories at this time.
The TEMPLATE\IMAGES Directory :

The IMAGES directory holds all images used within SharePoint 2007.
The TEMPLATE\LAYOUTS Directory : The LAYOUTS directory is another one of those directories that you should pay attention to. If you ever see /_layouts/ in the URL of one of your SharePoint sites, the aspx page will be in this directory. You will also notice the odd .ascx (control template), .js (JavaScript) and .master file within this directory. I am not sure why Microsoft didn’t tidy these files up and put them in more appropriate directories – as you become more familiar with SharePoint you will notice little inconsistencies like this.In the LAYOUTS directory is application.master, the master file for all of the “admin” type pages, such as upload.aspx. When you begin to look at site customisation and branding you will see that application.master is one of the files that will need to be looked at.

The 1033\IMAGES directory : contains many of the images used in publishing sites, such as the thumbnails for each of the different pages types. There are also icons in this directory.The 1033\STYLES directory : contains additional cascading style sheet (CSS) files.The MOBILE directory : contains a series of aspx pages that are optimised for mobile devices.The STYLES directory : contains one file, corefixup.css – more of an afterthought by Microsoft?
The TEMPLATE\Pages Directory :

The Pages directory contains three aspx pages that are pulled in as subpages to other aspx pages.
The TEMPLATE\SiteTemplates Directory :

A slightly misleading directory name as the SiteTemplates directory actually contains all of the SharePoint Site Definitions. It is in this directory that you would create any new site templates. There is a sub-directory for each site definition. Each sub-directory will contain at least an XML directory and a default.aspx file. The aspx file is the initial home page that is displayed when a site definition is used in SharePoint.

The XML directory :

This will contain at least an ONET.XML file, which defines the setup of the site definition, such as which Features to load, where the web parts go and what they are, which document library templates to assign.There will be extra files in some of the directories but they are used to provide the extra functionality that the site definitions require.When creating new site definitions, you will place your directories here. Please have a look at our blog for creating custom site definitions in more detail.
The TEMPLATE\SQL Directory :

The SQL directory contains a series of XML and SQL files. Some of these are used to define SharePoint configuration and content databases. You should not change these files.
The TEMPLATE\THEMES Directory : The THEMES directory contains 22 sub-directories, one for each theme that is available within SharePoint. Each sub-directory contains all of the files required for the theme, including all the images and the cascading style sheets.You can create your own custom theme and place it within the THEMES directory. Please visit our blog Creating Custom Themes.
The TEMPLATE\XML Directory :

The final directory, XML, contains XML and XSD files that are used in configuration of SharePoint. You shouldn’t need to venture in this directory, but if you do, be aware that any file you modify may be overwritten by SharePoint Service Packs.
alerttemplates.xml : Used to change the look and feel of Alert Notification emails for each list, web or custom types in your SharePoint Environment. You can set custom branding based on your to your email alerts.
BASE.XML : defines base types for lists that apply globally to all the SharePoint Web sites.
DOCICON.XML : This file is used for mapping file types to particular icons. To add the new icon to the file type follow below steps.1). To add a .pdf (Adobe PDF) file name extension, add the following line to the ByExtension section in this file—
'<' Mapping Key="pdf" Value="pdf16.gif"/ '>'.2). Add the file pdf16.gif (use Google Image Search to get this image) to the Program Files\Common Files\Microsoft Shared\web server extensions\12\Template\Images.
FLDTYPES.XML : Used to define how various SharePoint field types are rendered.
fldtypes_hold.xml : Used to define the hold status pertaining to entities realted to Records Management Policy. Note: This file is meant for internal use and it is recommended not alter the contents.
fldtypes_publishing.xml : Used to define the publishing field types like HTML, Links, Summary Links etc. In case of creating a new custom publishing field type, say Address (with validation) then a new entry related to this filed type has to be added to this file.All other xml files with prefix fldtypes are cutom built field types. Yet another notable field type is Business Data field. This field type is defined in fldtypes_spsbizdata.xml.
htmltransinfo.xml : Used to define the how to open various documents stored in the sharepoint server. The mapping entry for a particular document in this XML file will tell SharePoint server to open the document in a particular client application. If the document conversion mapping is not found in this file, SharePoint will prompt the user to download the document.
SharePoint is flexible enough for you to create custom properties by creating custom XML files in this directory.

Unable to add selected web part(s).

Sometime when we try to add a web part we might get the following message:

Unable to add selected web part(s).
Assemblies that implement ASP.NET Web Parts and are installed into a partially trusted location, such as the bin directory, must be compiled with the AllowPartiallyTrustedCallers set for import to succeed.

Solution:

Add the follwing to the AssemblyInfo.cs

using System.Runtime.InteropServices;

using System.Security;


[assembly: AllowPartiallyTrustedCallers]

This should work.

Friday, May 29, 2009

Quick notes about MOSS 2007 and WSS 3.0


1) We often try to open Document library in Windows Explorer View.(Action->Open in Windows Explorer). Sometimes, we might get the error "Your client does not support operating the list with Windows Explorer".



The reason behind this is that the URL on the address bar for Windows explorer view has a constant length. As it exceeds the length, it throws the error. The maximum number of characters for the Url of Windows Explorer view is 100. If it exceeds, we will be facing this problem.

Solutions:
a) There is some hot fix available for the browser to support this exceeding character limit issue. The installation needs to happen on client side. (http://social.TechNet.Microsoft.com/Forums/en-US/sharepointadmin/thread/f054897a-3572-4c66-bcb9-f9c35b834a55). I have not tested this solution.
b) Simply, we can rename the folder/file name  to shorter length , so that the number of characters does not exceed the specified limit. (It works).


Thursday, May 28, 2009

Deploying web parts in MOSS 2007

Web parts play vital role when it comes to user interface in share point technologies. The steps to create and deploy the web part are as follows:

Creating Web Part Solution

1) Open Visual Studio 2005 and create a new project. Select the project template as Web Part.


2) In my case, I am naming the solution as MySampleWebPart. The cs file and the Solution Explorer would look something like this: 

3)  Add few controls and render the same. The sample code would look like: 

 

4) To this project add a xml file and name it as manifest.xml. The contents of this file should look like:

The Deployment Target attribute can be WebApplication/GlobalAssemblyCache based on the requirement.

The safe control entry would be required for the web part to be registered safe. It would contain the namespace and assembly details. You can find them in Project properties. 

5) Build the solution and ensure that you do not get build errors.

6) Now, we need to create a CAB project for deploying the solution. For this, click on the solution name, Select Add -> New Project. This would open a pop up window with the project types. Select the project template as CAB Project

In my case, I am naming the CAB project as MySampleCodeSetUp. 

7) Right click on the CAB project (MySampleCodeSetUp), Select Add-> Project Output. This would give a pop-up window for selecting the project output group. Select Primary Output and Content Files. Click OK.

8) Now, build the solution once again. Ensure that there are no build errors. The successful build would create the file MySampleCodeSetUp.cab which would contain all necessary files for web part deployment.

Deploying the web part solution

 1)      Open the command prompt and type the command cd  C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

2)      Run the stsadm utility to add the solution. The command for adding the solution is: stsadm -o addsolution -filename MySampleCodeSetUp.cab. If the solution was added successfully, you would get the message, Operation was completed successfully. You can verify the same in Central Administration-> Operation-> Solution Management. Here you can find the newly added solution.

3)      Now, we need to deploy the solution. You can do it manually in the Central Administration or use the stsadm utility. The stsadm command for deploying the solution is: stsadm -o deploysolution -name MySampleCodeSetUp.cab –url http://servername (url of the share point site)

4)      You can find the dll for the web part at C:\Inetpub\wwwroot\wss\VirtualDirectories\\bin 

Populate the web part gallery

1)      Open the sharepoint site (top level site) . Site Actions->Site Settings-> Modify All Site Settings.

2)      Under Gallery you can find Web Parts.

3) Click New and select the new web part which was newly added. Click the button Populate Gallery on the top.


4) Open the share point site. Go to Site Action-> Edit Page. Click on Add Web Part . This would populate all the web parts which can be added. Here , we can find the newly added web part. Select the web part MySampleCode and Click Ok.



Friday, May 1, 2009