Tuesday, August 30, 2011

SPUtility.SendEmail Characters Limitation per line

SPUtility.SendMail has a limit on the number of characters in one line in the mail body. One line should not exceed 2048 characters.
However there is no restriction on the total number of characters displayed in the email body.

Friday, August 19, 2011

Better way of organizing documents - Folders or Metadata?


One common question among SharePoint users is - How to organize documents in a SharePoint Document Library? Some go with folders, others like to tag their documents with metadata.
End of the day, it should be simpler to add/manage/search documents.
Both the approaches have pros and cons...  Below I have listed down few pointers on when to use folders and when to use metadata.
Common Activities
Folders
Metadata
Security
 Provides option to restrict or manage access at folder level
 None.



Navigation
1.       Folders may look a neater approach, with the URL showing the folder name.
2.       But as the no. of folders increase, it becomes difficult to find documents that are in the Nth level of the hierarchy
3.       There is a limitation of 260 characters for the length of the folder path in total
1)       Metadata can be used to create views which display a subset of information based on the filter criteria.
2)       SP 2010’s Managed Metadata service allows metadata based navigation which gives navigating to documents a new experience



Url
 Folder names form portions of the Url of the SharePoint resources the folders contain.
 None.



Search
 Basic search on the folder names
 Metadata is indexed by SharePoint search and will return results based on keyword searches.
SP 2010 search based on Managed Metadata helps is obtaining results with better relevancy.



Sorting
 None.
 Metadata can be used to control the order in which items are displayed in list views.



Filtering
 List views can be configured to show only the list items contained within a folder and its sub folders.
 Metadata can be used to control which items are displayed in list views.



Grouping
 None.
 Metadata can be used to group list items together in list views. List views limit grouping to two hierarchical levels.

As you can see above, both have some advantages and disadvantages.
[More details coming soon]

Monday, April 18, 2011

Display form URL of a list item or folder

The below code provides a generic way to form/build URL to the Display form of a list item or folder. This code makes use of the default dispform specified for the list through the property splist.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url.

using (SPSite oSPSite=new SPSite("< site url > "))
            {
                using (SPWeb oSPWeb=oSPSite.OpenWeb())
                {
                    SPList oSPList = oSPWeb.Lists["ListName"];
                    SPListItem oSPListItem = oSPList.GetItemById(item_id);
                    string displayUrl;
                    string webUrl = oSPWeb.Url;
                    try
                    {
                        displayUrl = oSPListItem.ContentType.DisplayFormUrl;
                        if (string.IsNullOrEmpty(displayUrl))
                        {
                            displayUrl = oSPList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        displayUrl = oSPList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;
                    }
                        
                    bool isLayouts = displayUrl.StartsWith("_layouts/", StringComparison.CurrentCultureIgnoreCase);
                    displayUrl = String.Format("{0}/{1}?ID={2}", webUrl, displayUrl, oSPListItem.ID);
                    if (isLayouts)
                        displayUrl = String.Format("{0}&List={1}", displayUrl, SPEncode.UrlEncode(oSPList.ID + ""));

                }
            }

Here, the displayUrl gives the link to the dispform of the item.


Saturday, April 16, 2011

Filtered Dataview Web-part using SharePoint Designer

Filtered Dataview web part - Our requirement was to show the related project tasks/issue in the dispform of the project details of the project list, something similar to the Out of the box Project management site template.

Here we are displaying the project tasks under the Project list, filtered by the lookup column "Project" in the Tasks list.

The filtering is done using XSLT using the SelectCommand property.

Steps:
Add the Data View underneath the Projects list form webpart in the dispform.aspx of project list and get the data you want to insert the view of.  Once you have the data view web part there showing all the data in the list (non filtered), switch to Code view.
In the inserted Dataview, just after the tag add the following (If there is already a DataSources tag, then insert only the ....tag.... )


 This is where the data view fetches its data. The "SelectCommand" property of that tag is what applies the filter we want. 
Explanation for the above datasource query is below:
It compares the ID value of the "Project" field in a project task with the current ID of the query string (i.e. currently displayed object).
What makes it work is Type='Integer' and LookupId='True'. This turns the Project value in the Project Tasks list into the equivalent ID. 
The {0} on the next line is the name of the parameter from the query string to compare to. So you'll need another line of code under the SelectParameters (which I can only imagine defines the parameters for data selection) tags.  After the default ListID parameter you should find something like the following:
Code Snippet

< asp:QueryStringParameter Name="0" QueryStringField="ID">
Notice the Name="0" is the same name between the brackets for the SelectCommand. What this basically does is create a parameter (I like to think of them like a variable) with the value of the ID from the query string. 

Tuesday, April 12, 2011

Survey List cannot have workflows

Recently found out that workflows cannot be attached to "Survey" lists in SharePoint. Even though we get to see the option to associate workflows in the List settings page, the workflow doesn't start once a new survey item is posted to the list.
The status of the workflow appears as "Failed to Start".


Refer the below KB article for more details
http://support.microsoft.com/kb/926370

Saturday, March 26, 2011

SharePoint Wiki page doesn't have Title field

Almost all the content types in SharePoint have the Title field, but one strange issue i encountered was while working on the wiki pages (with the Wiki Content type). The content type is called "Wiki Page".

This content type doesn't have the 'Title' field.

In future when dealing with the Wiki pages, mainly when accessing the Wiki page content programmatically, don't use SPListItem.Title. This will return System.ArgumentException.

To access the wiki page title, access the property SPListItem.Name

Thursday, January 20, 2011

STSADM Extensions for rescheduling Timer Jobs

Managing the timer job schedules is not easy in SharePoint. To update the schedule of a timer job, the code needs to be modified or we should have an admin screen (some tools available on codeplex) to edit the timer schedule.


One of the other simpler option that i found is to use the stsadm extensions created by Gary Laponite - http://stsadm.blogspot.com/. These extensions provide lot of options on the command line. Here lets see how to use the stsadm command line extensions for updating timer job schedule. These extensions have a prefix "gl" to the normal stsadm operations.


1) Get information of a timer job:
    stsadm -o gl-getjobinfo -job "Timer Job" -URL
   This command gives the details of the timer job like Timer schedule, type, next occurrence, when the job last ran etc


2) Set the schedule for specified job:
This has many options. We can set the timer job schedule as a Minute/Daily/Monthly/Daily schedule.




Parameters:
        -job
        -url
        -scheduletype


For a daily schedule:
        -beginhour
        -beginminute
        -beginsecond
        -endhour
        -endminute
        -endsecond


For a minute schedule:
        -beginsecond
        -endsecond
        -interval


For a monthly schedule:
        -beginday
        -beginhour
        -beginminute
        -beginsecond
        -endday
        -endhour
        -endminute
        -endsecond


For a one time schedule
        -time


Ex:
stsadm -o gl-setjobschedule -job "Timer Job" -URL  -scheduletype daily -beginhour 13 -beginminute 30 -beginsecond 00 -endhour 14 -endminute 00 -endsecond 00


Running the above command sets the timer to run the job daily at 1:30 PM


This way we can reschedule the timer job


Thanks to Gary Laponite for these wonderful commands. Check out the other stsadm extensions @ http://stsadm.blogspot.com
http://blog.falchionconsulting.com/index.php/stsadmpowershell-commands/