Thursday, February 26, 2009
but, it didn't work...WTF??
How sweet it is when you try to use a "standard" attribute and when you realize that...Gasp It hasn't been implemented By MS (That was the real answer that they gave us!)
We have spent a few days on this bug, so I just blog it hoping that the one who is looking for solution find it!! There is no solutions but creating a feature that will replace the announcementList feature. This feature that you can call "CustomeAnnouncementList" will be a copy/Paste of the basic Anouncement List feature amended (in the element.xml file) with the rowlimit attribute inside. Then you have to activate this feature on all sites. Bingo! Of course, if you don't want to see 2 anouncement list in your available lists, you will also have to deactivate the old feature.
Cheers & Good luck
Wednesday, February 25, 2009
My problem was this one :
"I need to display on a specific page the default view of a list, BUT beside each items of this list must be displayed a checkbox in order to be able to select items on this list"
The solution I chose was to recreate a clone of the defaultview that will never be displayed to the users but that will be selected as SPView of the ListView I create on my page.
Here we go...
1/ My Page takes in parameter the ID of the list I'm working on, i call the parameter "List":
Guid ListId = new Guid(this.Page.Request["List"]);2/ Then whenever I reach the page, i check whether the view already exists, if not i create it cloning the default view and adding to it a checbox field. If the clone of the actual defaultview exists i just use it! Easy! In my code below, the listview object is called Select_List
Now, let me explain the code a little bit.
1/ How to create a column Checkbox in a list?
It's quite tricky cause you must create the column using a CAML definition.
Sorry for the "+" but it's for my code lisibility! In fact you just create a field where the display is an HTML input component !!
2/ OK, but now, i have the display How do I get my checkboxes values after postback ?
Well, let's continue to be tricky!! I just create two Hidden field on my page
And on my validation button i fill it before validation using a JS function called fill_ids
The js function simply puts inside the listSrv_Items the ids of each item in the list, and checked_ids will finally contain the list of items ids that are checked.
here we go for the js that i manually add to the page in the render method:
Now my field checked_Ids will contain the ids of my checked items so in my Btn_valid_Click; i just have to use it to do anything I want! That's it!
Some Regexp, some recursivity and here we are :
The function basically return null if the URL passed is not a list URL, and return the list ID whenever you pass an URL to it. It also works when you pass the url containing some allitems.aspx after the name of the list...
Hope it helps
Tuesday, February 24, 2009
But I have never really found a full answer. I'm gonna try to give a full one!
First, be aware, that there are many ways to catch the SharePoint errors, but to my knowledge, only this one is fully supporter by Microsoft, cause it uses an HTTPModule which is a supported way of working!
1/ Create your HTTPModule
The class you are about to create inherits System.Web.IHttpModule
During the Init of the module, add an event handler that will listen to the Error. It should be something like
And now declare your event handler function:
I was basically doing it differently, using an arrey of AllErrors, but it didn't give always the good exception, so I used a part of the code created by Anupam Ranku on his blog http://www.codeproject.com/KB/sharepoint/Handling_Error_Centrally.aspx.
From him, I took the fact that using
I was directly going to the first innerexception. Simple and efficient !!!
2/ Create an Error page
On the Page_Load of this page, just verify that the last exception exists
Design your page the way you want it to be!
3/ Modify your web.config
For this, let's assume that you have created a feature, and you have already a classe inheriting
So of course you have already created your 4 overidden functions (
The FeatureActivated method will be launched after activation of the feature (smart name for a method that do so!!!), so what you want to do is to add your http module to the web.config (Carreful: it must be added to ALL the web servers of your farm), to do this let's use this :
What is this AddNewHttpModule function?? Calmos papillons! it's coming!
So this method basically add to the web.config the HttpModule you just created... BUT... one last thing but not the least... This SPWebConfigModification is something really interesting...with one limit, it only add the Modification at the end of the list and for error handling, the httpmodule you enter must be put at the beginning of the httpmodule section of the web.config.... So far, I didn't manage to do it programmatically....so manually, i have to go inside each web.config to cut/paste the new line... (sigh)....
To conclude, See the image of my VS project, in order to understand the wya the project is built (I'm addicted to WSPBuilder!)
4/ Addendum -April 2009 - Catch WebParts Error
So far, the feature worked almost perfectly. I only add one issue with Webpart errors. SharePoint, on the error page sometime add a link to go to the Webpart management page. The HttpModule can't see the difference between those kind of errors and others...(until now) !!
I have added a function in the httpModule that recognize whether an exception has been thrown from a webpart or not... here it is!
At the end of the Application_Error method, just add a new Application variable :
In your error page, you just have to add a if then else, to manage this case.