Dienstag, 27. März 2007

Sharepoint Eventhandler updating fields for a document in a document library

I got a task where documents can be published to a document library. Published documents should get properties attached that are stored in a seperate custom list with a custom content type.

The documents derive all from that custom list content type.

So I wrote an eventhandler for an Updated and Added event to load all the fields from the custom list entry and if the document has also that fields, wrote the value.

At the end i just put in properties.ListItem.Update() and it updates the item. That was my development machine.

In production there came an error across: The document has to be checked out to update its properties. Ah, ok.

Because its only metadata in my mind and the user cannot control if the file gets checked out and i don't want to increment the version number i searched for an alternative method. I could'nt turn off "versioning" and "checkout requirement".

Long term, short answer: just call listItem.SystemUpdate(false).

This bypasses the "normal" checkout and list settings and just updates the item and does not increment the version number (if you use the second ctor with the bool. bool incrementListItemVersionNumber). BE SURE TO KNOW WHAT YOU DO :)

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.systemupdate.aspx

Montag, 19. März 2007

Sharepoint Custom Application Pages

If you are one of those who want to add custom application pages to sharepoint, then the following infos might be useful:

  • Put your aspx files in the _layouts folder (directly, not an sub folder)
  • If you get errors, edit the web.config file in the _layouts folder to allow debug and turn custom errors off. (not in the web.config of the sharepoint.app)
  • Its easier to use incode aspx files rather than code behind files (perhaps someone could use a combination of this and the last item in this list)
  • If you want the look and feel of other sharepoint pages use the application.master file
  • This project might be useful: http://subliminalsystems.com/Downloads/ItemAuditing_Whitepaper.doc
  • A different approach: http://ablog.apress.com/?p=1369

Whats left is that i want to use the Sharepoint User Controls like the other application pages but how do i do that?

Is this possible? Perhaps someone can tell me

UPDATE:

What works for me is to create a project under the _layouts folder and mark the aspx files as Build Action = none. Additionally i removed the iis application. it can compile but not debug but thats ok at the moment. Inline code files does'nt even call the Page_Load Event in my case.