Bitter Coder
sour code and astringent experiences
Saturday, November 10, 2007
More SharePoint hacks
Here are some more SharePoint hacks (continuing on from my last post
here
)
First off some hacks for the
SPGridView
which is actually a pretty useful control, but fails to do a few things, like displaying attachment columns as-per SharePoint's default List views (with a little paper-clip symbol), and the second (and much more annoying) it doesn't use the current users regional settings / timezone for formatting DateTime values.
The hacks:
Attachments bound field
Localized DateFime bound field
And finally support for a ListForm replacement web part - after trying to customize the ListForm to suit a customers requirements by creating a CustomListForm in SharePoint designer I gave up in disgust because it's just too limited in what it lets you achieve, and worst of all, it breaks attachments support! So I wrote a small web part to replace it, which allows for fine-grained control of visibility and editability (if that's even a word) of each field, and as an added bonus it doesn't break the attachments functionality. I also wanted to add additional links/buttons to the form which triggered a save including validation etc. - so I did a little hack to implement that as well.
Web part to replace New or Edit ListForm
Adding links to the Edit Form web part
I might have a few more to post before the end of the project - but it's almost wrapped up, so these may be the last for a while.
Hopefully someone out there finds them useful.
.Net
|
hacks
|
SharePoint
posted @ Friday, November 09, 2007 9:38:26 PM (New Zealand Daylight Time, UTC+13:00)
Comments [8]
|
Trackback
|
Tracked by:
"Sharepoint Hacks - field visibility" (Bitter Coder)
[Trackback]
Sunday, November 11, 2007 9:17:23 PM (New Zealand Daylight Time, UTC+13:00)
Actually I saw these a few days ago and thought 'damn those will be useful' ... they went straight in my Google Notebook :)
Casey
Sunday, November 11, 2007 11:30:15 PM (New Zealand Daylight Time, UTC+13:00)
It's not pretty code sadly, but you might find it useful... heh
Alex Henderson
Monday, November 12, 2007 8:11:03 AM (New Zealand Daylight Time, UTC+13:00)
Pretty code? Hell, if you can make any code that talks to SharePoint 'pretty' I will buy you a very large crate of beer!
One small question ... threw your code into a project this morning to shortcut my way through another business requirement, and noticed 2 lines of code that wouldn't compile:
List fields = new List(fieldsToRender);
List buttons = new List();
I fixed them with:
List<FormComponent> fields = new List<FormComponent>((IEnumerable<FormComponent>)fieldsToRender);
List<FormComponent> buttons = new List<FormComponent>();
But... what 'List' were they meant to be pointing to?
Also as a note for anyone else who uses the code, it also requires another piece of code from Alex, CustomTable (http://wiki.bittercoder.com/CustomTables.ashx)
Casey
Monday, November 12, 2007 8:31:31 AM (New Zealand Daylight Time, UTC+13:00)
Ack, I'm guessing Screwturn wished away the angle brackets because it I didn't escape it properly :)
I've added in the obligatory <esc></esc> and now everythings back to way it should be.
I'd be interested to know how you get on with that code Casey... it was gutted from a component tailored to a clients needs, so I haven't given it a great deal of testing in it's current form.
Alex Henderson
Monday, November 12, 2007 11:28:46 AM (New Zealand Daylight Time, UTC+13:00)
Well - I'm busy hacking away at it at the moment ... the replacements I made to the generic list bit worked after a little tweaking ... then the first problem I hit was that it was intended as a base type rather than to be instantiated. OFC me being lazy, I just dropped it into my site.
Firstly, those 'yield' statements had to go ... :) Sorry a bit behind here ...
Secondly my comment above was slightly wrong (I picked the wrong type so it would compile but not run), correct version is :
List<FieldToRender> fields = new List<FieldToRender>((IEnumerable<FieldToRender>)fieldsToRender);
As such, it sort of works, but doesn't ... because it displays every damn field that SP knows about, and then it can't write back to them ... hence you commented TODO Add logic etc
Then I replaced the EnumerateFields method (for the time being) rather than derive. With a few alterations it seems to display the fields that can actually be edited, and lets me add things... more work to come, I'll feed back what I can ... this will be a great basis for the task I was given (volunteered for) on Friday!
protected virtual IEnumerable EnumerateFields(SPList list)
{
List<FieldToRender> newList = new List<FieldToRender>();
foreach (SPField field in list.Fields)
{
if (field.Type != SPFieldType.Counter && field.ReadOnlyField == false && field.Hidden == false && !IsInternalField(field))
{
bool isVisible = true;
bool isWriteable = true;
newList.Add(new FieldToRender(field, isVisible, isWriteable));
}
}
return newList;
}
protected string[] SPInternalFields = new string[] { "Author", "Editor", "Created", "Modified" };
protected virtual bool IsInternalField(SPField field)
{
string fieldName = field.InternalName;
foreach (string internalField in SPInternalFields)
{
if (fieldName == internalField) return (true);
}
return (false);
}
Casey
Monday, November 12, 2007 12:15:28 PM (New Zealand Daylight Time, UTC+13:00)
OK- small quirk ... It is sort of working ... in DisplayMode.New I can add items to my list, but attachments are failing ...
The list item was saved, but one or more attachments could not be saved.
Could not upload file C:\Documents and Settings\Administrator\Desktop\MsUnitTest.xml.
Actually it is lying, the attachment is saved, and linked, but the error displays. Go back to the main list view and the update is there, along with the file.
If you view the item with DisplayMode.Edit the attachment shows twice:
Title *
Attachments UnitTestTemplates.xml Delete
Attachments UnitTestTemplates.xml Delete
And if you do try to delete the attachment it removes it from the screen, but when you hit OK you get:
Failed to get value of the "Attachments" column from the "Attachments" field type control. See details in log. Exception message: Specified argument was out of the range of valid values..
If you have any ideas let me know, or if I get any bright spark of genius and fix it, I'll let you know ...
Casey
Sunday, November 18, 2007 7:06:01 PM (New Zealand Daylight Time, UTC+13:00)
Hi,
I managed to deploy and add the web part to SharePoint Custom List form. The web part displays input fields for all the list's fields. In your post you mentioned that you're using an XML configuration file, can you please post a sample configuration file? Furthermore, can you please provide more guidance about deploying this solution (web part and configs)...
Thanks for your reply. By the way... great work!!
LebStar
Monday, November 19, 2007 10:03:02 AM (New Zealand Daylight Time, UTC+13:00)
Hi LebStar,
I'll post more about this tomorrow when I have time - but here's the code I use for establishing which columns should be displayed at all:
private static bool IsHidden(SPField field)
{
return (field.Hidden || field.ReadOnlyField || field.Type == SPFieldType.Attachments);
}
foreach (SPField field in list.Fields)
{
if (!IsHidden(field))
{
if (!field.ShowInNewForm.HasValue || field.ShowInNewForm.Value)
{
// include this field on the new form
}
if (!field.ShowInEditForm.HasValue || field.ShowInEditForm.Value)
{
// include this field on the edit form
}
}
}
When I get a little more time I'll post some more code about how I had this web part auto-generate a default column configuration file for new/edit modes which could then be edited to change the order/visibile/editability etc. It's pretty trivial though.
Cheers,
- Alex
Alex Henderson
Comments are closed.
© Copyright 2008 Alex Henderson
Theme design by
Bryan Bell
newtelligence dasBlog 1.9.6264.0
| Page rendered at Saturday, November 22, 2008 8:05:10 AM (New Zealand Daylight Time, UTC+13:00)
Search
FeedCount
Tags...
.Net (82)
.Net Reactor (4)
.net user groups (9)
2008SummerRoadTrip (1)
ActiveRecord (1)
architecture chat (54)
ArchitectureCamp2007 (2)
asp.net (1)
Astoria (1)
Auckland (1)
base4 (9)
batching (1)
binsor (1)
blog (4)
books (1)
C# 3.0 (9)
cambodia (9)
CAML.Net (1)
castle (39)
china (8)
codecamp (2)
codeplex (3)
dapper.net (1)
DevDefined Ltd. (4)
DirectShow.Net (1)
DLR (1)
DSL (3)
EAUG (1)
Enterprise Architect (5)
Enterprise Library (1)
F# (1)
feedburner (2)
Friendster (1)
generics (1)
googlegears (1)
hacks (3)
hardware (3)
hongkong (2)
hyper-v (1)
ideas (1)
IoC (21)
IronPython (13)
IronRuby (2)
jobs (1)
Languages (2)
laos (8)
LINQ (7)
LiveId (1)
LLU (1)
Local Government (1)
MDA (1)
MDD (1)
microsoft (1)
Model Driven Development (1)
mono (1)
monorail (2)
Movies (1)
Music (1)
nDepend (1)
news (1)
NHibernate (2)
NUnit (2)
nvelocity (1)
OAuth (6)
office (1)
OpenSocial (1)
orcon (1)
photos (1)
php (1)
PostSharp (1)
powerpoint (1)
presentations (1)
ReSharper (1)
REST (2)
rhino commons (2)
rhinomocks (5)
Ruby (1)
SaaS (1)
scm (1)
Screen Architect (1)
SharePoint (5)
silverlight (1)
Splicer (4)
SQL2008 (1)
supcom (1)
svn (1)
Syzmk (4)
thailand (6)
Tools (2)
Tortoise SVN (1)
trac (2)
Travel (36)
Unity (2)
vietnam (7)
vista (2)
vmware (1)
volta (3)
VS2008 (1)
WCF (3)
wiki (2)
wikipedia (1)
Windows Server 2008 (1)
windsor (6)
WinForms (1)
wix (2)
WPF (2)
xmlrpc (1)
yahoo pipes (1)
Who am I?
Alex Henderson
Auckland
, New Zealand
Managing Director at
Dev|Defined Limited
"Self Confessed Coding Junky for 15 years"
Mobile:
+64-21-402-969
Email:
bittercoder 'at' gmail 'dot' com
MSN:
bittercoder_nz@hotmail
Skype:
alex.devdefined
Navigation
My Bookmarks (Delicious)
My GoogleReader - shared items
My Photos on Flickr
My Wiki
Catch NZ Limited
DevDefined Limited
tools.devdefined.com (Trac site)
New Zealand DotNet User Group
Screen Architect
Seismic Technologies (Syzmk)
Splicer - The .Net Video Splicing Library
On this page....
Blogs I read by New Zealanders...
Alex James
André Meurer @ Olympic Software
Andrew Dixon
Andrew Peters
Bennie Johnston
Blog:: Craig Pringle
Blogging is probably just a fad, but just in case...
Buzzrick's TileEngine Game Platform
Chris Auld
Chris Crowe's Blog
Chris Johnson
Clifton Johnston
Code Climber
Craig Box
Daniel
Daniel Wissa
Darryl Burling
Dave Dustin
Duncan Bayne
Floyd Burgess
Gabriel Smith
Geekzone blog
Grant Archibald
Grant Drake
Ivan Porto Carrero
Ivan Towlson
Jeremy Boyd
Jithen Singh
John-Daniel Trask
Josh Hektor
Juha Saarinen
Keith Nicholas
Kevin Daly
Mark Rees
Maruis Marais
Mauricio Freitas
Mindscape
My Blog (Alex Henderson)
Nathan Mercer
Nic Wise
Nick's Blog
Nigel Parker
Paul Andrew
Paul Lo
Peter Jones
Phil Cockfield
Public Address
Rod Drury
Sean McBreen
Simeon Pilgrim
Software Development and stuff
Stefan Schulz
Steve Schapel
Steven Kempton
The Blog of Dave5
The Book Diary
The Voice Of Reason New Zealand
Thoughts from Mirality
Tim Haines
Blogs I read on Castle...
Andrew Hallock
Ayende
Brian Romanko
Dan Bunea
Dru Sellers
Eleutian SpeakENG Development Blog
Gabriel Schenker
Hamilton Verissimo
Insane World
Insert Catchy Title Here
Jeff Brown
Ken Egozi
Marc-André Cournoyer's blog
Matt Berther
Nick Parker
Roy Osherove
Roy Tate
Technorati: http://castleproject.org
Wendy Friedlander
BlogMap
Del.icio.us
Wishlists
Sign In