Thursday, June 29, 2006

Problems with InfoPath Forms on Forms Server

I have started to experiment with forms server and have noticed some things that are good to know, and I also noticed that in news groups and forums there are some FAQ's that need to be answered.

FAQ : "Where do I get VSTA"?
People who try to add code to web enabled forms are getting prompted that they cannot use this until they install VSTA. Most people dont bother reading the whole message and go to the internet and look for it. VSTA is a part of the office12 installation, but when you choose the default installation it doesnt get installed. You will have to go to "add-remove programs", click on office 12, and pick "change" to get to the feature selection screen:

Notice how the box next to infopath is gray? this is because not all the components were installed (namely the VSTA).

Click the gray box and select "run all from my computer" and then click the "continue" button to install. next time you open infopath you will have the ability to add managed code to your forms.

FAQ - I wrote code in my form in jscript or vbscript, but I now want it in c#

Since web forms only support the .net managed code and not the scripting languages, you will have to remove the client code, and change the scripting language to a .NET language.

To do that, open the "tools" menu, select "Form Options" and switch to the "programming" section. Here you will have the button to remove existing code, and after you do that you can switch to a different language of your choice.

Notice in this screen that task panes will not be ported to the web form (naturaly).

Text boxes cannot be vertical in web forms

Rich text boxes cannot contain images

Master-detail not supported in web forms
Ok, this is dissapointing, and hopefully microsoft will figure out a way to do this in future releases or service packs. Meanwhile, it is not possible to use the Master-Detail functionality in a form published as a web form to the form server. (note the validation task pane)

Wednesday, June 28, 2006

Excelent new free training material for sharepoint 2007!

The sharepoint team have just released some online training material that is worth to check out. (my thanks to Lawrence who wrote about this in his blog)

Developer Clinics:

MOSS 2007 Hands-on Labs:

WSS V3 Hands-on Labs:

I have just started the development course, and already learned some new exciting stuff. I will share as soon as I finish the course!

Tuesday, June 27, 2006

Sharepoint 2007 - User Or Group Column programatic access

You may have read about this new exciting column available now in sharepoint lists. This column allows users to select from a directory of users by searching. This is a great feature, and today I had to find how to fill that field programatically.

It turns out that the field is (internaly) a look up field - which means it expects a number as an input.

You cant do :

  1. item["Assigned To"] = "administrator";
  2. item["Assigned To"] = "administrator@demo.com";
  3. item["Assigned To"] = "demo\\administrator";

Instead, you have to specify the user ID from the user's list:

item["Assigned To"] = 1;

But how to tell what ID does a user have? The only way I know of is using the "Users" property of the SPWeb object. Lets say you want to assign the field to ishai@demo.com (you only know the email). you can use the following code:
item["Assigned To"] = item.ParentList.ParentWeb.Users.GetByEmail("ishai@demo.com").ID;

If you know the domain name instead of the email, you can use the Users.GetCollection function and pass the domain name as a string array, then get the ID of the first item in the results:
string [] domainName = new string[1];
domainName[0] = "demo\\ishai";
item.ParentList.ParentWeb.Users.GetCollection(domainName)[0];

Liked it? Please kick me! kick it on SharePointKicks.com

Sunday, June 25, 2006

Sharepoint 2007 - Column Limits

Introduction This is a question that I saw being asked in the groups many times, and no one gave a definite answer - how many columns (aka fields) can a sharepoint list hold in the new version?

Executive summary There are no hard limits to the number of fields you can create in a list. However, the more fields you add, the less usable your list is.

Details In the old version (2003) there was a finite number of fields or a mix of fields that you could add. This was well documented in the planing guide, but for the current beta there are no such guidelines. Some people speculated that the limits will remain the same, while others speculated there are no limits, or that the limits are within the thousands.

Well, I was bored and decided to find out the hard way. I wrote this small c# application to create a custom list and add fields to it. I ran it on different number of fields (3 times for each number) and checked the time it took to complete the loop.

Results The results show that sharepoint has no limit that I could reach. I managed to add 2000 text fields to the list without any errors. However, the more fields I added, the more it took to add more fields. This is to be expected, and also - the more fields I added the more time it took to open the list form (for exact numbers I intend to do a future test).

The following chart shows how the preformance of the code that adds the fields to the list degraded the more fields there were in the list. I also tested adding fields in batches (add 100 fields, stop add 100 more and compare the time) and the results were about the same - its not how big your loop is but rather how many fields are there in the list.
Conclusions

It is interesting to note that there doesnt seem to be a limit to the number of fields. I have reached 2000 and succeeded (I will try over night to push the limit...what do you thing? a million?).

More important however is the matter of preformance. You can see the preformance of the code dropping the more fields it has to create.

Regardless, a form with hundreds of fields is not user friendly and is not recommended. My guess is that the only people who will rejoice with this answer are people who intend to use sharepoint as thier data container for custom applications and will display custom forms to users instead of using the sharepoint forms that show all fields at once. I hope this helped answer any question you may have had. If not, post a comment and ask! If you did like it, please kick me (using the link below)

kick it on SharePointKicks.com

Hands on lab for workflow

Once again, thank you Mark Harrison,
This new download from Microsoft was published on the 23/6/2006 and is "a set of 10 Hands-on Labs for Beta 2 of Windows Workflow Foundation. Each lab is approximately 60 minutes of work. The download is a Windows Installer package that includes lab manuals for each lab, pre-requisite files for the labs and sample completed solutions for each exercise in the labs". download here

Thursday, June 22, 2006

Whats new with list views in Sharepoint 2007?

List views are the one of the most important flexibility feature in sharepoint. They enable us to create customized views for specific purposes, showing different fields and applying different filters on the same list.

I guess we all expected to have more exciting views options in the new version - like maybe grouping by more than two fields, or having more formulas for the filter (how about [Manager] as a token? how about a datediff formula?)

However, in the current beta there are not alot of changes, but some cool things were added:

  1. Gantt view Allows showing a list as a project gantt chart. This requires you to specify 4 fields - "title", "start date","end date" and a "precent complete" field. Nice of microsoft to let us pick the title field. So many times we get stuck with using a predefined field for this.
  2. Grouping - select how many groups per page.
    In the previous version it was very annoying how shareoint handled paging of list items in a grouped view. When you created a view that grouped items by a field, and limited the number of item per page to (for example) 5, if the first group had more than 5 items the user would only see one group in the page, and didnt know that there are more groups unless he clicked the "next page" link. Now, we can choose to page groups as well as items. Good going!
  3. Preview pane style Ok, I have some idea of what microsoft were trying to achieve here, but I wont hazard the guess. The only thing I can say about this option is that it doesnt work. See in the following screen capture what happens when I choose this style for a document library. Selecting this: Leads to this:

Summary:

I am actually disappointed from the changes to the views. one is cool, the second is actually a design fix that should have been done as a service pack in the previous version, and the third is a bug. I also expected more forumlas support in the filter and more style options. I hope microsoft has plans to improve that before release.

Mark Harrison writes about content management with MOSS.

Great contibution by Mark.

Also includes the source code for the demos:

  • Custom Field Control ... a Windows Media movie selector
  • How to add a button to the HTML editor

Here is a link to the presenation and sample code files. zip password is harrison

Wednesday, June 21, 2006

Email in Workflow is super flexible!

The workflow designer that is shipped as part of frontpage looks great. It reminds me in part of the rule wizard in infopath - I wonder if there is a connection?

Anyway - there is one thing that I was worried about, but it turns out microsoft were way ahead of me. The emailing feature in the workflow designer is sooooo flexible its almost perfect (in computers nothing is ever perfect. ask six developers to write the perfect "hello world" application and you will get at least 6 different applications, each developer defending his solution to the death)

What do I like about it?

Well, for example - you can specify a rule to send an email when something happens in the workflow.

Well, obviously! it wouldnt be a workflow if you cant do that! What is really nice is that you can set formulas to any of the email fields - the "to", "cc", "subject" and body (where is the bcc you ask? I told you nothing is perfect!).

Examples of such a formula -

  1. Workflow lookup - send to an email that is in the meta data of the item in the workflow. This is great for task lists - if the "assigned to" field changed you can make a workflow rule to sent email to the person it was changed to!
  2. User who created current item - this is preety obvious. I guess that user will want to be in the CC of any email generated by the process...Another good idea for this is for discussion boards - I have to try getting the workflow to send a user who asked a question (started a thread) an email about every answer.

If you think about it, the workflow designer actually replaces most of our needs for event handlers. It is so simple to develop, and with actions such as "send email", "set field in current item" and "create list item" and so on, its going to be very usefull for deploying smart solutions fast.

Thanks for that MS!

Monday, June 19, 2006

Sharepoint or WebSphere?...well, sharepoint of course!

Just for fun, I ran this search in "google trends" and guess what - starting from the middle of 2004, sharepoint wins!

MOSS (Sharepoint 2007) event handlers - register only by code

With the sps2003 event sinks, you had to link them to a document library using the "advanced settings" screen in the UI.

This meant that people with permissions to change the list could disconnect the event handler, or even worse -see the settings in the xml data property. This meant that we couldnt use sensitive settings there - for example - a password for a database.

In the new version, linking a list\site to an event handler is done by code. You actually have to write an application that will link it. I am sure microsoft will provide us with a generic application (or if not, its easy enough to create one...I would start on one if I knew that MS isnt going to do it...)

Anyway, this means that we can use the event handlers for preventing list changes - for example we dont want to allow the list administrator to delete an important field that is required by our application, so we write an event handler for the fielddeleting event and cancel the deletion if the field is the sensitive one. Since the list administrators cannot disable the event handler, they will not be able to delete the field.

I wonder (and need to research) how many event handlers can be attached to the same list\site? hmmm....

This new advance is great, and I cant wait to see how we use it in projects. Any ideas for some event handlers that will be needed by everyone?

Event Handlers in MOSS (Sharepoint 2007)

I just saw this amazing video downloaded from the 2007 Office System: How Do I ScreenCasts about event handlers.

did you realize there are now decent event handlers?

The new model actually lets you catch different events in different functions (unlike the 2003 event sinks where you had one sink function and you had to do a switch to identify what type of event it was).

Also, it is now possible to get synchronous events - for example cancel an update to a list item using the itemupdating event.

But more (much more) important than that - the new event handlers support events not just for items (item created,item changed) but also for list (field changed, field deleted, field added, list created, list deleted and so on) and for site (site deleted....).

The only limitation they admit to have is that there is no event handler for sitecreated. This they claim can be done using a feature.

I started thinking about why you should trap a "fielddeleted" event and such like, and ofcourse the answer was list replication. I had lots of applications done around event sinks in 2003 where we defined mirror libraries so that the event sink copied a document once it was uploaded to the mirror libraries. one of the problems was how to change the meta data if the master library was changed. This can solve this issue easily and keep all libraries in synch. ofcourse the copy mechanism doesnt need to be in an event handler in sps2007 - it can be implemented as a workflow step instead, but lets leave this until we develop some best practices as to when to use an event hander and when to use a workflow...

Web Part Development - careful with the bin!

I have read around what other bloggers wrote about custom web parts, and found that most say to copy the dll file to the _app_bin directory, in spite of what the SDK says-"Web Parts cannot be stored in the _app_bin directory."
I could not find a difference between the two folders. Putting a web part in either one seems to work just as well.

However, there is one thing to note from the SDK - both folders have by default low trust levels. A simple web part will work, but when you try to use sharepoint object you get the dreaded sharepoint.security error that throws your users to the maintnance page. yuck!

To make sure this doesnt happen, either put the dll in the GAC (requires signing) or follow the directions from the SDK to allow web parts in the bin directory to run with trust:

Step 3: (Optional) If using the bin directory, set special security attributes
By default, code access security permissions for the bin directory are low; only pure execution is allowed. Although the sample in this walkthrough can run with the minimal trust level, in most cases you need to elevate these permissions to make your assembly run correctly, for example, if your Web Part requires access to the SharePoint object model.

There are two ways to elevate permissions:

  1. (Recommended) Create a new trust policy file, and point your web.config file at the new file. This option is more complicated but it gives you a precise attribution of permissions for your Web Parts. For more information about trust policy files, see Microsoft Windows SharePoint Services and Code Access Security.
  2. Raise the net trust level of the bin directory. In the web.config file in the Web application root, there is a tag called with a default attribute of level="WSS_Minimal". You can change this level to WSS_Medium. While this option is simpler, it grants arbitrary new permissions you might not need and is less secure than creating a new trust policy file.

To raise the trust level of the bin directory Locate the web.config file in your application root and open it for editing. Locate the trust level tag, . Change the trust level to WSS_Medium.

Answer to comment - enhanced rich text field

Someone posted a comment asking about rich text in discussions. So I popped over to my testing machine and checked out the new "Enhanced rich text" field that is new in MOSS.

As you can see, "Enhanced rich text" is an option for a "multiple lines of text" field. by default in a discussion list it is already set to true.

Enhanced rich text enabled by default for discussion lists

When in the list, you get more controls then the regular rich text editor. these include adding a table:

Rich text control includes table controls

When clicking the "insert table" button, the following screen pops up allowing to specify columns and rows:

Specify number of columns and rows

SharePoint Forms - InfoPath on the Web!

I had a chance to work a bit with InfoView - a solution by my company (Unique World) to convert infopath forms to web forms.

This is such a great solution! you can use the great infopath UI to design a form, and then with a click of a button - KA-BOOOM and its a web page allowing people to fill in the form and view it and such like.

One problem with the version I worked on was that to configure the form so that when people submitted it it would save into a sharepoint form library required manual code intervention. Also, you had to write a page to link to the form and its different views.
NO MORE!
The new "SharePoint Forms" was announced, and now you just install it on your sharepoint server, and you can create "sharepoint forms libraries" which automatically detect if the client has infopath installed or not, and open the web-based form if not!!! and the default behavior when the user submits is to post to the document library.

COOL!

There are still some issues when converting - not all the infopath features are supported in the web form, but that is only to be expected. Every release brings more supported features, and if people will be nice enough to request it here, I will post sample code of things I did to enhance infoview forms...

Official Site
http://www.sharepointforms.com/Default.aspx
Demo (very recommended)
http://www.sharepointforms.com/Content/ViewDemo.aspx

Sunday, June 18, 2006

Windows SharePoint Services V3 Link Galore V2

Just found this post - looks like a nice list (more so if the guy updates the list) list of sharepoint 2007 links

Best practices writing webparts for sharepoint

This is one of the most important articles I have read lately: Using Disposable Windows SharePoint Services Objects

What it explains is that when you develop web parts and use the sharepoint objects (like spsite and spweb) you have to dispose of them because the garbage collector wont.

The article also contains code examples for the recommended three ways to do this: 1. use "dispose" 2. use "using" 3. use "try, catch, and finally blocks"


Example for using "using":
String str;

using(SPSite oSPsite = new SPSite("http://server"))
{
  using(SPWeb oSPWeb = oSPSite.OpenWeb())
   {
       str = oSPWeb.Title;
       str = oSPWeb.Url;
   }
}  
Example for using "try, catch, and finally blocks":
String str;
SPSite oSPSite = null;
SPWeb oSPWeb = null;

try
{
   oSPSite = new SPSite("http://server");
   oSPWeb = oSPSite.OpenWeb(..);

   str = oSPWeb.Title;
}
catch(Exception e)
{
}
finally
{
   if (oSPWeb != null)
     oSPWeb.Dispose();

   if (oSPSite != null)
      oSPSite.Dispose();
}


I would recommend that every web part developer go through this article and maybe even print it and nail it to his monitor...

Thursday, June 15, 2006

Links open in new window? you made MS laugh!

I just cant believe that MS didnt notice that this is one requirement that all customers ask from customizers. We need a way to specify if links will open in new windows or not. how hard can that be? just add a property to the URL field type that the list administrator can change! arrrrrgggghhh!

Wednesday, June 14, 2006

Sharepoint 2007 - Some Thoughts

New in Lists

  1. List view web parts now have the filter and sort in the titles drop downs – no need for full menu to get that!
  2. Lookup fields can now have multiple values.
  3. Aggregation web parts out of the box.
  4. List item security. permissions include “full control”, “design”, “contribute” and “read” – the same as for the site. Read is simple, contribute means edit and so does design. I am guessing that only with full control the users can change the security settings for the item
  5. List Item versioning. This is great because some things we did in InfoPath because we didn’t have this.This means that we can now track a list item as it is changed. We can go and view the item’s history and see who changed it and when. This is important for issue tracking and record management (I suppose that’s how SharePoint implements record management) A great thing about it is that in the version histoy page you actually get for each version the fields that were changed. So (for example) if I changed the priority of a task item, you will see in the list of versions that today, Ishai changed the priority to “2” and created version “3”. How great is that?!

Bugs

  1. Clicking cancel when editing a view throws an error: “list does not exist” exchange web parts out of the box.
  2. Titles in discussion boards are not shown correctly – you see a “” tag before and after each title.

Accessibility

  1. Still no doctype in the html (hey Microsoft! You are adding it by default in frontpage, why not in SharePoint?)
  2. Still no language meta tag
  3. Page viewer web part still does not render a title for the iframe (error 12.1)
  4. The default CSS still does not respond well to changing the text size in the browser.

All in all I would say that accessibility didnt improve, which is sad. This means that accessibility sensitive organizations (like most if not all of the goverment departments) will have to invest in developing alternative styles and custom solutions for better accessibility.

Record Management

  1. Creating a record management (record repository) workspace automatically creates a document library that is linked to an email address (“mail enabled”) that is created automatically. This way you can easily set up a procedure where a secretary who wants to log that something or other was received or sent only has to send an email to this address.

Monday, June 12, 2006

SharePoint 2007 First Try

Today I started a mega-project that will result in a huge sharepoint 2007 deployment. This means that in the next few months I will be working and developing with the 2007 version and will be able to give here a report of my findings!

So today was the first day I got to play around with it and actually find things out.

Discussion Board View Bug
One of the first things I found is a bug (how strange...). I wonder if anyone else saw that, or if its a known issue (I couldnt find anyone talking about it in the newsgroups). I will post this in the news groups and see what comes out and update you:
When you are in a discussion board list, you cannot create new views. you can only modify the default view.
The new views are actually created (when you go to list management page you see them) but you cannot switch to them (The drop down box for selecting a view only has the default view), and when you manually write the URL to a view, you get "thrown" back to the defaul view.
This does not happen with regular lists (otherwise I expect it would have been shouted about all through the internet).

People Field
On a positive note I found one of the new features very very nice - a person selector field. When you create such a field the user can either write a person's email or login name or click on an address book icon to search for a person in the directory. You can set it up so he can only select users or he can select both users and groups. I didnt have a chance to play around with that field yet, and I can think of a lot of improvements it will need (how about limiting the number of users? how about limiting the selection to a certain branch in the active directory hierarchy?) and I am sure us custom solution developers will want to expand its capabilities.

Workflow
This is nice. I just opened a list and there it was in the advanced settings. I could define a workflow for items! There are a couple of built in events and actions - you could for example tell it that when a new item is posted, send an email to the user specified in the [blank] field. How nice is that??? The number of workflow types is limited (I think only 4 workflows), I guess thats what MS meant when they called it "workflow foundation". Again, us custom developers are in for a lot of work! Thanks MS!

List Event Handlers
YES! YES! YES!
ok, maybe that was exagerated, and with the new workflow I am not sure how often we will want that, but it seems like such a great way to extend lists! If until now in sharepoint 2003 we had to use InfoPath forms if we wanted event handlers, no more! now we will be able to do wholesome solutions based on pure sharepoint lists. I wonder where the catch is...

As always, I would appriciate any comments from you people. tell me if you also encountered the view bug and what you think of the possible solutions emerging from the new architecture. I will keep you all posted.