Archive for Sharepoint

Truncating Characters in Body Column of Announcements

// November 10th, 2008 // No Comments » // Sharepoint

There are few options available in order to do this.

You can try the following:

1) Create a new column “TrimmedBody” of type Text and limit the number of character to say 10 or whatever works for you.
2) Open a Sharepoint Designer and Create a new workflow on your List. Set workflow to start automatically when new item is created.
3) Add one action i.e. “Set Field in current Item”. Select TrimmedBody in field selection and select Body in value selection.

You action should look Set TrimmedBody to Announcement:Body  (where Announcement is name of the list)

See if this works because of the character limit on TrimmedBody Column. (It did not work for me. Despite the fact that I set character limit to 10, it workflow copied all the text from Body. :))

In order to rectify this problem, I just created another column(”CalculatedBody”)of type calculated and my formula looks like this:

=LEFT([TrimmedBody],10)

This should work. There are other ways to do it as well, for example:

1) You can also check Paul’s codeplex utility which provides custom function.

2) You can use event handler on the list which will trap ItemAdding event of the list and update the list item, but then you will have to write the code deploy the event handler etc.

3) You can use VS workflow, and that way, you have more flexibility in terms of writing code.

Troubleshooting SPView: ViewFields Doesn’t Return the Fields Selected in the View for Display

// October 28th, 2008 // No Comments » // Sharepoint

Earlier, when I was working on a web part, I ran into an issue; SPView.ViewFields wouldn’t return the fields I have selected in the view.

The following code:

SPView oListView = docList.Views[this.ViewName];

SPViewFieldCollection ViewcollListItems = oListView.ViewFields;

returned Columns in the default view i.e.: Type, Name, Modified, and Modified By, for the document library. I was passing the custom ViewName which I have created. So basically, it returned the default columns.

I stumbled across the following thread on MSDN forum and found the solution, thanks to Michael.

If you are using SPContext in your code, then change the following line from:

SPWeb contextWeb = SPContext.Current.Web;

to the following:

SPWeb contextWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl);

This did the trick for me.

Hiding a Custom List Toolbar Menu Item from Non-Administrative Users

// October 2nd, 2008 // No Comments » // Sharepoint

In order to hide a custom list toolbar menu items from non-administrative users, use the following:

<CustomAction Id=”SharePoint……”
RegistrationType=”List”
RegistrationId=”100″
GroupId=”SettingsMenu”
Location=”Microsoft.SharePoint.StandardMenu”
Sequence=”1000″
Title=”Configure my App”
Description=”….”
Rights =”ManageLists”
ImageUrl=”/_layouts/images/myimage.gif”>
<UrlAction Url=”~site/_layouts/myApp/Configure.aspx?List={ListId}&amp;SiteURL={SiteUrl}”/>
</CustomAction>

Rights attribute Specifies a set of rights that the user must have in order for the link to be visible. If not specified, then the action always appears in the list of actions. To specify multiple rights, separate the values by using commas. The set of rights are grouped logically according to AND logic, which means that a user must have all the specified rights to see an action.

Reference: http://msdn.microsoft.com/en-us/library/ms460194.aspx