Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Tuesday, September 7, 2010

How to add new aspx pages to SharePoint programmatically

There are two different solutions to create new aspx pages in SharePoint.

First one is using of SharePoint Services RPC Methods:
1. Create query in XML format to call NewWebPage method:
<?xml version="1.0" encoding="UTF-8"?>
<Batch>
<Method>
<SetList Scope="Request">DocLib_ID</SetList>
<SetVar Name="ID">New</SetVar>
<SetVar Name="Cmd">NewWebPage</SetVar>
<SetVar Name="Type">BasicPage|WebPartPage</SetVar>
<SetVar Name="WebPartPageTemplate">LayoutID</SetVar>
<SetVar Name="Title">AspxTitle</SetVar>
<SetVar Name="Overwrite">true</SetVar>
</Method>
</Batch>

Where:
  • DocLib_ID is ID (GUID) of document library where do you need to create new aspx file.
  • BasicPage|WebPartPage type of aspx. Use BasicPage for page without layout (LayoutID =0) and WebPartPage for all other terms
  • LayoutID specifies page layout [1...8]
2. Call SPWeb.ProcessBatchData method with this query.
3. If you need to create aspx file in document library subfolder, create it in doclib and move to the necessary subfolder with SPFile.MoveTo method.

But this approach doesn't work for meeting workspace where you can create several pages with access via convenient multi-page web part.
To create new pages there you need to use SPMeeting.AddPage (AspxTitle, InstanceID, out resNewPageUrl) method. Set InstanceID = 0 to create page directly in the Workspace Pages library.

Thursday, June 17, 2010

SharePoint Web Parts don't work with "Incorrect properties format" error

Issue: Sometimes, when you open SharePoint 2007 site, you see that all web parts show

"Web Part Error: One of the properties of the Web Part has an incorrect format. Windows SharePoint Services cannot deserialize the Web Part. Check the format of the properties and try again."

Furthermore, sometimes this site and its web part work correctly: you see all web part working. This behavior doesn't dependent from browser version or host. You're just clicking "Refresh" and see different results: web parts work or don't work.

Possible reason: If you have more than 1 SharePoint front-end on the target farm, check, please, how do they work. If some of front-ends have problem with free disk space, you can observe problems with web part functionality. Eventlog on this front-end contains errors with ASP .NET 2.0 problems during the page generation.

During the "Refresh" in browser you can get results from different front-ends, it depends from your SharePoint load-balancing infrastructure. So you can see correct pages from "good" front-end and bad pages from "unhealthy" SharePoint front-end.

Issue is absent after disk cleanup on the "unhealthy" SharePoint front-end.

Friday, April 9, 2010

SharePoint 2010 Client Object Model

Now you can work with SharePoint remotely. Client code communicates to the server through Client OM which uses Client.svc WCF service to communicate with SharePoint Server. Client.svc service uses Server OM as per client request and returns the result to the client in JSON format.

Thursday, April 8, 2010

Built-in SharePoint constants

http://blog.hompus.nl/2010/02/05/prevent-hardcoded-sharepoint-ids-in-your-code

The SPBuiltInFieldId class contains 314 GUID’s for the default SharePoint fields.
The SPBuiltInContentTypeId class contains 34 content type ID’s for the default SharePoint content types.
The FeatureIds class contains 16 GUID’s for the MOSS publishing features
The FieldId class contains 61 GUID’s for the publishing fields.
The ContentTypeId class contains 10 content type ID’s for the publishing content types.
The PropertyConstants class contains 42 names of the standard user profile properties

The WssFeatureIds class however is public and the only place the 24 WSS feature id’s are available.

Because this class is not documented I list all fields:

AnnouncementsList
BasicWebParts
ContactsList
CustomList
DataConnectionLibrary
DataSourceLibrary
DiscussionsList
DocumentLibrary
EventsList
GanttTasksList
GlobalContentTypes
GlobalFields
GlobalMobilityRedirect
GridList
IssuesList
LinksList
NoCodeWorkflowLibrary
PictureLibrary
SurveysList
TasksList
TeamCollaboration
WebPageLibrary
WorkflowHistoryList
XmlFormLibrary

Tuesday, March 23, 2010

Move a SharePoint Content Database


It's pretty easy:

Sometimes it's the easy things that are hard to track down concrete instructions for! Here are step by step instructions for moving your MOSS content database to a new server, followed by the things to watch out for.

You have two initial options, doing a backup and restore within MOSS to move the data, or doing it at the SQL/STSADM level. I prefer the latter, as it isn't nearly as inclined to fail and leaves you with more flexibility.

1) Find the content Database

These are listed under Central Admin->Application Management->Site Collection List

2) Backup the content database

You could alternatively detach it, and copy it. Just doing a backup in SQL Server 2005 Management studio is easier.

3) Restore content database to new server

Copy the BAK file to new server. Create an empty DB in Management Studio, restore from backup, you may need to change an option in the "options" tab of the restore dialog to get it to work. (Overwrite db).

4) Create Web App on new Server

Central Admin->Application Management->Create or extend Web App->Create New Web App.

5) Associate restored DB with new Web App

Central Admin->Application Management->SharePoint Web Application Management->Content Databases->

Remove Content Database from your new web app.

Now use STSADM to add restored DB to this web app

c:\program files\common files\microsoft shared\web server extentions\12\bin on new server is where you can find the STSADM.

run this command from there.

stsadm -o addcontentdb -url http://yourwebapp:port -databasename yourcontentdb -databaseserver yoursqlserver

6) Run ISSRESET from command prompt.

Caveats:

  • Make sure your running the same service pack level on both source and destination sharepoint if possible.
  • Make sure you install all webparts, solutions, features, etc on new server before you restore the content database, so that it can find all the features it's looking for.
  • Make sure you copy any files that may be living in the file system that you need, sometimes people have css/javascript here. (This refers to files in the hive)
  • Leave your old site and contentDB intact until you get the backup running on the new server, this way your ok if there is a problem.
  • DON'T try this with your config database! It won't work!

Monday, March 22, 2010

Get all users with Full Control for the web

Instead of user enumeration and check roles for each user, you can get role assignments for web and get all users for corresponding role.

Like this:

using(SPWeb web = SPSite(webUrl).OpenWeb())

{

SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;

SPRoleDefinition roleDefinition = roleDefinitions["Full Control"];

foreach (SPRoleAssignment roleAssigment in web.RoleAssignments)

{

if (roleAssigment.RoleDefinitionBindings.Contains(roleDefinition))

{

SPPrincipal oPrincipal = roleAssigment.Member;//it can be SPUser or SPGroup, you can process and add it to the result

}

}

}

MSDN forum

Wednesday, March 17, 2010

Import WSS 3.0 Doclib to SharePoint 2010 with Content Migration API

It works.
You need just to change the schema version in SystemData.xml file to new SharePoint 2010 version ("14.0.0.0" Build="14.0.4730.1010" for my lab).

Ghosted vs Unghosted and where the file lives

Ghosted == Uncustomized == lives on the file system

These are generally deployed using features or site definitions


Unghosted == customized == lives in the content databse.

These files are either files that have been modified using SharePoint designer or uploaded through the user interface.

Generally Ghosted/unghosted were the terms used with SP 2003, while customized/uncustomized were introduced with 2007, supposedly to make the terms easier to understand.

http://platinumdogs.wordpress.com/2009/08/13/uncustomized-ghosts-vs-unghosted-customizations/

From MSDN forum: Original thread

Wednesday, March 10, 2010

SPExportSettings.FileMaxSize - limitations

MSDN describes that FileMaxSize allows to set 2GB.
But it looks like that it works with range from 1 to 1023 only, at least it tries to work :)

For any values >= 1024 the export uses default cmp size = 24MB

Also is interesting that stsadm has 1024 as a maximum cabsize value.

FileMaxSize works, at least I can get 10MB package. But the export fails on my lab with FileMaxSize > 100: "FatalError: Export ran out of memory while compressing a very large file. To successfully export, turn compression off by specifying the -nofilecompression parameter."

I have tried to export 6GB site and export works only with FileMaxSize <= 100. I think "100" can depend from real site data size.

There is interesting point that error can be raised due the manifest.xml size. I think that true is somewhere near, because compression works with default size. Probably the compression can not split some long description of object from manifest.xml between several files.
Looks like a bug.

Wednesday, March 3, 2010

SPExportObject.IncludeDescendants vs SPExportObject.ExcludeChildrens, what's the difference?

Really, what's the difference between children and descendants?

MSDN doesn't say about this difference: IncludeDescendants, ExcludeChildren.

But it looks like that IncludeDescendants is more flexible.

Export result shows that:

· ExcludeChildren = true is the same with IncludeDescendants = SPIncludeDescendants.Content.

· ExcludeChildren = false goes to IncludeDescendants = SPIncludeDescendants.All.

Ok, let check how the export depends from IncludeDescendants value and ExportObject type.

SPDeploymentObjectType.Web:

SPIncludeDescendants.All all web content and its sub-containers (like doclibs and lists) with sub-sites is exported

SPIncludeDescendants.Content – only root web content (doclibs, lists) is exported, without sub-sites

SPIncludeDescendants.None – exports only web property and service containers (like galleries). Usual doclibs and lists are not exported. In this mode export result doesn’t contain any custom aspx files from root web folder. /_themes, /images subfolders are excluded from the export also.

SPDeploymentObjectType.List

SPIncludeDescendants.Content, SPIncludeDescendants.All – full list content is exported

SPIncludeDescendants.None – only list properties are exported, no content

ExcludeChildren – doesn’t work for List because it maps to SPIncludeDescendants.Content or SPIncludeDescendants.All, those have the same export result. Note: MSDN says that ExcludeChildren works for List, but I do not see difference between results for ExcludeChildren = true or false. But it works for Folder!

SPDeploymentObjectType.Folder

SPIncludeDescendants.All (or ExcludeChildren = false) full folder and its sub-folders content is exported

SPIncludeDescendants.Content (or ExcludeChildren = true) and None – only folder properties is exported!

Tuesday, March 2, 2010