Posts

Showing posts with the label Development

Opening an Infopath form library template from Infopath in a link

I've found a lot of bad info on how to do this and it's not well documented so hopefully this helps someone: first create a JavaScript function so that your links aren't super long: <script type="text/javascript">             function OpenForm(absSiteUrl, siteRelFormUrl, siteRelSaveUrl)             {                         var formUrl = absSiteUrl + siteRelFormUrl;                         var saveUrl = absSiteUrl + siteRelSaveUrl;                         var formSvcUrl = absSiteUrl + "_layouts/FormServer.aspx?XsnLocation=" + formUrl;    ...

Including a JS file for a custom ribbon control CommandUIHandler without using a ScriptLink CustomAction or Custom Page Components

I've been struggling lately with the proposed solutions for including the javascript for CommandUIHandler's CommandAction and EnabledScript attributes.  Thus far I have only seen the following examples: JavaScript directly into the attributes (messy), Including a ScriptLink command action (bad because then the script file is included in every page where the feature is activated causing bloated pages) Creating a page component (overcomplicated) Instead of all this, I created a pattern which loads the js file on the fly with javascript and keeps your ribbon development more compact (note I have JQuery loaded in the master page, if you don't have this then you'll have to either load jquery dynamically or reference the elements without JQuery): <commanduihandler    CommandAction="javascript:                              ...

Quickly determine which PID corresponds to which App Pool's w3wp.exe

This is a command that will quickly let you know which w3wp.exe you should be debugging on Server 2008 (IIS7, since the App Pool isn't listed in Visual Studio's 'attach to process' dialog). go to \Windows\System32\inetsrv and run "appcmd list wp" and you'll get a list that associates App Pool and PID

Understanding Sandboxed Solutions

There are several components/processes that are involved in the execution of sandboxed solutions.    For a developer, it's critical to understand how coding/debugging various types of solutions changes based on the type of solution.  Here's how the execution goes in a nutshell: When the sandboxed code is called, the Execution Manager (running in the w3wp.exe) makes a call to an application server running the User Code Service (SPUCHostService.exe).  The User Code Service then tells the Worker Service  (SPUCWorkerProcess.exe) to load the sandbox code.  The code is then verified to ensure only calls to the subset of the API allowed by the Sandbox API are called.  The worker process then executes the code against the Worker Proxy (SPUCWorkerProcessProxy.exe) which has full access to the SharePoint API (but the sandboxed code has already been disallowed from using the non-subset portion of the API by the Worker Service). When debugging sandboxed solution...

Getting a usable SPItem URL to a display form

This is definitely from the "I can't believe I hadn't blogged this already department". When you try to use the SPListItem.Url property you wind up getting a url that's relative to the site (even though it starts with a '/'). I've written this method that will return a list item url and takes into account the fact that the urls differ when they're lists or document libraries: private string GetItemUrl(SPListItem listItem)         {             string result;             string itemUrlTemp = listItem.Url.Replace("Lists/", "");             string siteRelativeListUrl = itemUrlTemp.Substring(0, itemUrlTemp.IndexOf('/'));             if (listItem.ListItems.List.BaseTemplate == SPListTemplateType.DocumentLibrary)                 result = SPEncode.UrlEncodeAsUrl(String.For...

Setting up a SharePoint 2010 Developer VM using VirtualBox

I spent a few hours this weekend creating a SharePoint 2010 Developer environment using the RTM. For now, I'm approaching my dev build the same way I had my MOSS 2007 VM set up - a standalone MOSS install with Visual Studio installed. Because I wanted to use a 64bit guest OS (64bit Server 2008), I decided to use VirtualBox as my VM solution, if you want to use VirtualBox, you can get it here . I should note that when I set up my VirtualBox VM I gave it 20GB of hard drive space which was not enough so I had to expand the drive ( described later orange text ). I'd suggest going to 40 or more if you can because Windows,SP2010, SQL, and Visual Studio take up about 18GB (and setting it up right the first time will save you from having to do this . Once I had Server 2008 installed on a VirtualBox VM I downloaded the RTM version of SharePoint from MSDN. I then attached the SharePoint 2010 .iso file to my VM, opened the mounted SharePoint 2010 image and ran the Prerequisite ...

Expanding a VirtualBox VDI file for Server 2008 x64 R2

I use virtual box as my SharePoint VM host because I want to be able to run 64bit Server 2008 R2 on my Windows 7 host machine.   When I first installed SharePoint 2010, the VDI (Virtual Disk for VirtualBox) I created was too small, so I had to expand it.   This is a bit of a challenge, but by doing some research I figured out how to do it. The process involves creating a new, larger disk and copying the original boot and main partitions to the newer disk.   This can be done with gparted .  and the steps to do so are well documented here However there are a few more steps you'll need to follow because you are using 64bit Server 2008 R2: After you've followed the above instructions, mount the newer larger drive as the Primary Master and mount the Server 2008 R2 ISO. Boot to the ISO (hitting any key when prompted) Choose your language then on the next screen select repair Select the partition and click ok Choose the command line option Switch to your c: drive ...

How to: Set up your SharePoint 2010 development environment

http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx

Programmatically Update Page Layouts

I updated my page layouts that I deployed as a feature, but found that I could not overwrite the Layout File. The solution was to add a new page layout and then you would have to associate the new layout with every page on your site that used it. Obviously with a site of any size you'd have a lot of manual work to get this done, so doing it programmatically makes for a much better (and thorough) approach. After you've got your new page layouts, you could do something like this (in your event receiver class): public override void FeatureActivated(SPFeatureReceiverProperties properties) { //replace current page layouts with new page layouts on all pages SPWeb web = SPContext.Current.Web; SwapPageLayout(web, "FullWidthContentWithTitleV1.aspx", "FullWidthContentWithTitleV2.aspx"); } private void SwapPageLayout(SPWeb web, string oldPageLayoutName, string newPageLayoutName) { PublishingWeb pubWeb = PublishingWeb.GetPu...

Web Part Styles

There are many examples of how to create a web part. However the best way to style web parts is not necessarily well documented, so I thought I'd offer up my approach and see what the community thinks. Basically I create my web part as a feature in a solution. Then, if my web part generates any code that requires styling I add a .css file to my feature directory. Next I provision the stylesheet of my web part to a folder within my site's "Style Library". Finally I add the code into my web part to add the stylesheet ("<link>") link to the header of the page that my web part has been dropped on. Most of the stuff is straightforward but here's how to provision a style sheet to the style library: Add a "provisioning.xml" file to your feature and reference it in the ElementManifest section of Feature.xml in "provisioning.xml" enter the following: <?xml version="1.0" encoding="utf-8" ?> <Elements xml...

WebPart Error: [ArgumentException: The serialized data is invalid.]

You may run into this problem. In my case I had a legitimate serialization error, but when I took out the offending code I was still getting the same error. I found the solution is to close/readd the webpart to eliminate the error.

A very nice tool

This CAML builder tool is pretty nice. If you're like me and haven't memorized the CAML spec, it's incredibly useful to test your query in this and then paste them into your code. U2U CAML Query Builder IMPORTANT NOTE: When using the trying to Query a list, remove the <Query> tags from the query otherwise the query wont do anything aside from return the whole list!!

Create Custom Applications Pages

At some point, in your WSS or MOSS customization and development process, you'll likely need to create a Custom Application pages. Custom application pages differ from site pages in that they are compiled and not customizable by the user. (to learn more about application pages click here ). If you'd like another good sample project to work off of, check out the CustomApplicationPages download Ted Pattison Group's download section. I'd also like to point out that Ted covers the specifics of this download in his book Inside Microsoft Windows SharePoint Services 3.0 which you can purchase in our SharePointers store .

Great SharePoint resource for Developers

Microsoft has a 10 part lab series which introduces several fundamental development tasks using SharePoint 2007. In addition there's a link to a VPC download that you can use to do the work. Check it out here

Adding a custom content type to a site definition

Today we'll be a adding a custom content type to our site definition we created in this post . The project that we're working with is an STSDEV project, so my project file structure reflects that. If you aren't using STSDEV you may need to make a few modifications. If you don't know what custom content types are, here's a good overview . The content type we develop here will extend the Document content type. We'll call it a Project Proposal. Now let's get to work. Step 1: Project Set up Aside from basing this project on the site definiton I created earlier, we'll need to add the Feature folders that reflect the structure on the server. Right click on the TEMPLATE folder in your project and choose 'Add New Folder', name this folder 'FEATURES'. Then add a folder under 'FEATURES' called 'ProjectProposalContentTypes'. Step 2: The feature definition file Since we want to deploy this as a feature we'll need to create the fe...

Creating and Deploying a Custom Master Page with STSDev

This is my second post on creating SharePoint solutions the easy way, with STSDEV. This time around I'll be enhancing my last post's project by adding a custom master page. This master page will start by using a base master page from Heather Solomon's site . If you don't already have it, download it. The base master page simply gives you a stripped down master page that you can enhance. We'll actually do some enhancements to give a taste of the power that you have over the UI when you choose to customize a master page. Step 1: Add the base master page to the project If you haven't already done so, download and unzip the base master page from Heather Solomon's site. Right click on your 'RootFiles\TEMPLATE\SiteTemplates\YourSiteTemplateName' directory and choose 'Add Existing Item' Select the base master page from your file system and click 'Add' Rename the file 'SharePointersDemoCustom.master'. Step 2: Editing the Defa...

Using STSDEV to create a solution with a Site Definition

In this post I'll give a basic overview of how to create a simple site definition using STSDEV. The purpose of using STSDEV is to give the project a standardized structure and to make use of the solution autogeneration. Here are the steps (Make sure you've downloaded STSDEV and run through the tutorials , or understanding this might be tough) Part 1: Generate the STSDEV solution Open Visual Studio and run STSDEV (should be an option on your tools menu if you ran through the tutorials, see above link) Choose to create an empty solution with C# assembly Click 'Create the Solution' After you create the solution, you'll need to open it from the file system. STSDEV does not automatically open it for you in Visual Studio. Part 2: Set up the project structure Even the most basic site definition needs at least 3 files: a webtemp.xml file, an onet.xml file, and a default.aspx file. So let's create these files in the appropriate places. right click on the 'Root...

ASP.Net AJAX and SharePoint

There's a project on CodePlex that integrates ASP.Net AJAX with SharePoint: I've only read the overview, but I've had lots of projects that I've wanted to use AJAX with SharePoint. So I can see how this will be a tremendous help. http://www.codeplex.com/sharepointajax

Programmatically get SPList items from a SPView

Another tip that you're sure to find some use for: Because SharePoint list (SPList) views (SPView) don't contain SPListItems or SPListItemCollections, if you want to programmatically retrieve list items from a list in the order specified by a view you've created you have to do it as follows (I've ommited, try-catch blocks and extraneous code to give you just the bare necessities) SPListItemCollection coll = spWeb.Lists["ListName"].GetItems(spWebInstance.Lists["ListName"].Views["ViewName"]); where spWeb is a SPWeb you've opened up from an SPSite object. and "ListName" and "ViewName" are the names of your lists and views, respectively.

Quick Reference for SharePoint Built in Fields

There are many instances where you need a quick, readable reference giving you the GUIDs for your FieldRef's in a content type definition file. Here's a handy xslt stylesheet that does the transform for you: <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wss="http://schemas.microsoft.com/sharepoint/"> <xsl:output method="html" version="1.0" encoding="utf-8" indent="yes" /> <xsl:template match="wss:Elements"> <html> <body> <h2>SharePoint 2007 Built-In Fields</h2> <table border="1" width="100%" style="font-size:10pt;"> <tr bgcolor="#9acd32"> <th align="left">Group</th> <th align="left" width="100">Field</th> <th align=...