Wednesday, June 3, 2009

How to test your workflow emails on a VM

I don't really want to install a mail server on my VM just to be able to test the emails that my Workflows generate. Instead you can do this in your web.config:

<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\IncomingEmails\" />
</smtp>
</mailSettings>
</system.net>



ref: http://msdn.microsoft.com/en-us/library/ms164241.aspx

Tuesday, June 2, 2009

That assembly does not allow partially trusted callers.

So I ran into something to be aware of today. We have a couple of Custom Field Types that we have written. As with all SharePoint CFTs, their assemblies are deployed to the GAC.

Today I was writing a Control (a Web Part would apply here just the same) that is deployed to the Bin. While deploying it I kept getting the annoying error: "That assembly does not allow partially trusted callers". I had my CAS policies defined and had the '[assembly: System.Security.AllowPartiallyTrustedCallers]' attribute in my AssemblyInfo.cs but I realized that I was getting the exception when I was trying to access the field value of an item that contained my Custom Field Type column (item["my CFT"])!

This was a good reminder that all CFTs should have the [assembly: System.Security.AllowPartiallyTrustedCallers] attribute, just in case, since you never know when a Web Part or some other partially trusted code will need to access them in the future.

Friday, May 15, 2009

Office 2003 datasheet view behavior

So for those of you out there still dealing with Office 2003 here in an annoyance that I found:

If you have a list with folders, and you go into one of the folders and try to create some items in DataSheet view, as soon as you create a row it will seem to disappear! What happens is that it actually gets created at the root level of the list! If you have Office 2007 the item gets successfully created inside the folder. The only way to get items into folders with 03 is to use the NewItem form but this can be a huge pain if you are trying to create 200 items at once.

Apparently this isn't something that is going to get fixed, it has to do with the fact that Office 2003 was designed to work with WSS 2.0 which did not allow you to create folders in Lists. Oh well, now at least you have been warned.

Friday, May 8, 2009

More DataForm WebPart goodies

Here is another handy control for use in data form web parts:

<td class="ms-toolbar" nowrap="">
<SharePoint:FormToolBar runat="server" ControlMode="New"/>
</td>


(Added the td class so it looks right)

This renders the normal listform toolbar (since if you just do Data View->Insert Data View, you don't get it).

Friday, May 1, 2009

DataSource CAML Keywords

So recently I needed to display the newest item added to a Very Large List via a dataform web part. The performance on SPQuery is pretty good as long as you return less than 2000 rows from your query. This means that you can't just return all of the list items from the datasource and then sort for the newest one. Instead I used some CAML keywords to help out. My DataSource query filtered on:

<Eq><FieldRef Name="Author" /><Value Type="Integer"><UserID /></Value></Eq>

and

<Eq><FieldRef Name="Created"/><Value Type="DateTime"><Today/></Value></Eq>

These two CAML rendering elements (for the current date, and current users ID). Helped the query return a very small number of rows, which could then be sorted by created date to show the newest.

Monday, April 27, 2009

EntityEditorWithPicker rendering

I was working with a custom lookup field type today that renders with a entity editor with picker (like a Person or Group field). I discovered that the required field validation for a SPFieldLookup fieldtype didn't actually seem to work in a dataform web part (I later found out that it works if you do a "Custom List Form" Dataform, I'll post on this later). My workaround was to embed some javascript in the page with the dataform to do some client side validation (because of the way it renders, the asp.net validator in SPD also won't help). I might write up a "how I did it" post on this in detail later, but for now I just wanted to mention an interesting thing I noticed, that the entityeditor actually renders with a bunch of hidden textareas, but the user is actually typing into a contenteditable div!

Friday, April 10, 2009

Attachments field in DataView

Ran into this the other day, if you include the 'Attachments' field of a list in a dataview web part (i.e. DataFormWebPart Single Item View) you get text that says Yes or No depending on if this item has any attachments. Not exactly the behavior I was looking for; probably not the behavior ANYONE was looking for... If you want to show links to the actual attachment the same way as the normal DispForm ListView webpart shows them, remove the xslt for the attachments field and instead put:

<SharePoint:AttachmentsField ControlMode="Display" FieldName="Attachments" runat="server" Visible="true"/>


Just to be clear, I believe this will only work on a list form page. Why the @Attachment's field can't just at least output you the attachment names is beyond me...

Wednesday, April 8, 2009

Finding the DataView Web Part EditPanel

So here is a useful tip...

If you are adding a data view part to a page in SPD and you click the "Dataview properties..." link in the contextual menu, you get the SPD properties screen that doesn't actually have all of the standard webpart Edit Panel (ie toolpart for you v2 guys) options (like Target Audience for example). To get the normal UI one, go to code view and right click your '' tag. On your contexual menu here you will see "Tag Properties...", click this and you will get the normal webpart EditPanel.

Thursday, March 26, 2009

How to filter a list on a specific date range (End User)

I have decided to add some end user focused entries as well for things that I get asked a lot...

I was asked recently about creating a filter on a list view for a specific date range.

To make a filter for a specific month you can do this:



You can also use the [Today] keyword in your filter. For example to create a view that shows all items with a date after the current date you would set your filter to date is greater than: [Today]. Or to have a filter show items in the last week you would set a filter for date is greater than [Today]-7 AND date is less than [Today]+1. Be careful to not put any spaces between the keyword and the - or + operator.

Remember to make sure your dates are in the correct format (mm/dd/yyyy) and are valid dates (ie 2/30/2009 won't work) otherwise you will get the "filter value is not in a supported date format" error.

Hopefully this help clarify any confusion that people may have.

Wednesday, March 11, 2009

Why can't I use Totals on a calculated column?

So you may have run into this frustration before: for some crazy reason, when creating views with Totals, you cannot include totals for Calculated columns (even if they are set to output as 'Number'!).

Here is a example situation:
You have a list of projects, each project has Q1 through Q4 values that you want to add up to give you a yearly total:



Easy enough, you just create a calculated column:



Now your list looks like this:


Here is where the frustration comes in, you want to see an average yearly spend so you create a view with Totals, unfortunately the calculated field doesn't even show up as an option!



This seems to me like an oversight from the product team, but at least there is an alternative method! If you view your list in datasheet view:



you can enable Totals here:



And magically your calculated column total shows up! Of course we wanted an average here, so just click the dropdown on your calculated column total field, and change the value to Average:



And there you have it. Be aware that for some odd reason the total will only display in datasheet view (if you change it back the other column totals stay but the calculated one disappears), but now you know how to find it.

Tuesday, March 3, 2009

Dataview DataSource not showing all files...

Ran into a situation today where a Dataview web part was showing some of the items in a Library but not all... It turns out that by default the datasource only shows files and folders at the top level. All of the items that are inside of folders or subfolders will not get returned.

The solution is to go to the 'Scope' parameter of your tag and change it to 'RecursiveAll'. This will cause your query to return all items regadrless of folder level from the data source. One thing to note, if your list or library is a Very Large List you need to be careful to set your 'Filter' parameters before changing the tag to 'Recursive' (Shows all files of all folders) or 'RecursiveAll' (Shows all files and all subfolders of all folders); in our case we were doing a dataform for a very large list so we set the Filter to ID = . If you are creating your DataSource in SPD and you don't set your Filter before changing the Scope to Recursive there is a good chance SPD will time out and/or crash trying to preview your data.

More info on Data Source configuration here: http://office.microsoft.com/en-us/sharepointdesigner/HA101326861033.aspx (just note that they are changing their data source properties BEFORE they add it to the page, this will run you into the timeout issue I described above for Very Large Lists so remember to add it to the page and edit the Scope by hand in Code View).