Wednesday, October 6, 2010
SharePoint 2010 Client Object Model: "(400) Bad Request" error
Tuesday, September 7, 2010
How to add new aspx pages to SharePoint programmatically
<?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>
- 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]
Friday, August 20, 2010
Django cache (storage)
Thursday, June 24, 2010
WikiEditPage.InsertWebPartIntoWikiPage - does it have a bug?
<div class="ExternalClassB93FFFFBB50E42E5B5D1BE5F906438A1">
<table id="layoutsTable" style="width:100%">
<tbody>
<tr style="vertical-align:top">
<td style="width:100%">
<div class="ms-rte-layoutszone-outer" style="width:100%">
<div class="ms-rte-layoutszone-inner"></div>
</div>
</td>
</tr>
</tbody>
</table>
<span id="layoutsData" style="display:none">false,false,1</span>
</div>
public static void InsertWebPartIntoWikiPage(SPFile wikiFile, WebPart webpart, int position){ if (wikiFile == null) { throw new ArgumentNullException("wikiFile"); } if (webpart == null) { throw new ArgumentNullException("webpart"); } string str = (string) wikiFile.Item["WikiField"]; if (position < 0) { throw new ArgumentOutOfRangeException("position"); } if ((str != null) && (position > str.Length)) { throw new ArgumentOutOfRangeException("position"); } SPLimitedWebPartManager limitedWebPartManager = wikiFile.GetLimitedWebPartManager(PersonalizationScope.Shared); Guid storageKey = Guid.NewGuid(); string str2 = Utility.StorageKeyToID(storageKey); webpart.ID = str2; limitedWebPartManager.AddWebPart(webpart, "wpz", 0); string str3 = string.Format(CultureInfo.InvariantCulture, "<div class=\"ms-rtestate-read ms-rte-wpbox\" contentEditable=\"false\"><div class=\"ms-rtestate-read {0}\" id=\"div_{0}\"></div><div style='display:none' id=\"vid_{0}\"></div></div>", new object[] { storageKey.ToString("D") }); if (str == null) { str = str3; } else { str = str.Insert(position, str3); } wikiFile.Item["WikiField"] = str; wikiFile.Item.Update();}
string StorageKeyToID(Guid storageKey){ if (!(Guid.Empty == storageKey)) { return ("g_" + storageKey.ToString().Replace('-', '_')); } return string.Empty;}
Friday, June 18, 2010
SharePoint 2010 Client Object Model, get folder Item
m_rootTrgUrl = web URL
mm_trgParentWebId = web ID
m_trgListId = existing list ID
srvRelativeURL = folder server-relative URL
using (var clientContext = new ClientContext(m_rootTrgUrl))
{
var trgWeb = clientContext.Site.OpenWebById(m_trgParentWebId);
var trgList = trgWeb.Lists.GetById(m_trgListId);
var query = new CamlQuery();
query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name=\"FSObjType\" />" +
"<Value Type=\"Integer\">1</Value>" +
"</Eq>" +
"<Eq>" +
"<FieldRef Name=\"Title\"/>" +
"<Value Type=\"Text\">" + folderName + "</Value>" +
"</Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
"</View>";
query.FolderServerRelativeUrl = srvRelativeURL;
var folderItems = trgList.GetItems(query);
clientContext.Load(trgList);
clientContext.Load(folderItems);
clientContext.ExecuteQuery();
switch (folderItems.Count)
{
// process query result
}
}
Thursday, June 17, 2010
SharePoint 2010 Client Object Model, attachment creation
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.
Thursday, April 22, 2010
Introduction to querying lists with REST and ListData.svc in SharePoint 2010
When you are getting started, the first thing you want to do is check and see if you have ListData.svc up and running. Like any SharePoint web service, it’s located in the _vti_bin folder of any existing site, so it will work with items relative to that site. Here is what a typical URL might look like.
http://
…
To get the data for this list via REST we simply just add the list name to the URL. In my case the name of the list is called Tasks. Here is what the URL would look like.
http://
you just want to know the status for a specific task (note that the site column is actually called StatusValue here), you can simply add it to the URL like this.
http://
In my case:
http://sp2010/_vti_bin/ListData.svc/Tasks(3)/StatusValue
…
You need to install ADO.NET Data Services v1.5 CTP2 on SharePoint front-end to get it working.
Friday, April 9, 2010
SharePoint 2010 Client Object Model
Thursday, April 8, 2010
Built-in SharePoint constants
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
Wednesday, April 7, 2010
Django sessions and forms in IE
Tuesday, March 30, 2010
Test Lint (Beta): Find common problems in your unit test code
http://site.typemock.com/test-lint/
- Microsoft Test Framework
- NUnit
- MbUnit
- XUnit.NET
- CsUnit
Tuesday, March 23, 2010
Move a SharePoint Content Database
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
}
}
}
Friday, March 19, 2010
Interview with Uncle Bob Martin (TDD, craftsmanship)
http://blog.typemock.com/2010/03/finally-entire-interview-with-uncle-bob.html
What is software craftsmanship all about?
Why TDD is not stupid
Confessions of a TDDer
TDD and unit testing adoption
Wednesday, March 17, 2010
Import WSS 3.0 Doclib to SharePoint 2010 with Content Migration API
Ghosted vs Unghosted and where the file lives
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/
Wednesday, March 10, 2010
SPExportSettings.FileMaxSize - limitations
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.
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!