Skip to main content

Blog de Alejandro Avila

Go Search
Home
  

 Documents

Paper Browser.8.5x11.Horizontal.pdfPaper Browser.8.5x11.HorizontalAlex Ávila
sketching.pdfsketchingAlex Ávila
website-stencil-template-a4.pdfwebsite-stencil-template-a4Alex Ávila
concept7_a4_sketching_paper_v01.pdfconcept7_a4_sketching_paper_v01Alex Ávila
mbti_sketching_concept7_a4.pdfmbti_sketching_concept7_a4Alex Ávila
PeopleSearchResultsCustomization.pptPeopleSearchResultsCustomizationAlex Ávila
Taxonomy-Sharepoint-2009.pptTaxonomy-Sharepoint-2009Alex Ávila
Adding JQuery to your Sharepoint
 
By providing the contents for the AdditionalPageHead Delegate Control that is used by all the out-of-the-box master pages, you can make sure the the jQuery library is loaded by all the SharePoint pages. The AdditionalPageHead Delegate Control allows multiple controls to provide contents, so it’s a great extensibility scenario. To accomplish this you need to build a web user control (ASCX file), that contains the script tag to load the jQuery library:

<%@ Control Language="VB" ClassName="jQueryControl" %>
<script type="text/javascript" src="http://weblogs.asp.net/_layouts//jquery-1.2.6.min.js"></script>

There is no code-behind file required. This control needs to be deployed to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES folder on the hard drive of every SharePoint Front End Web Server. Additionally you need to have a feature that will add the control to the AdditionalPageHead Delegate Control, the feature’s manifest will look like this (assuming the control is named jQueryControl.ascx):

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control
    Id="AdditionalPageHead"
    ControlSrc="~/_controltemplates/jQueryControl ascx />
</Elements>

The feature can be scoped to any level, when it’s activated on a certain level, all the pages will automatically have the script tag in their HEAD tags. Pretty cool, isn’t it?

via: http://weblogs.asp.net/jan/archive/2008/11/20/sharepoint-2007-and-jquery-1.aspx

Personalize Your Portal with User Controls and Custom Web Parts
 

[Personalizable,

WebBrowsable,

WebDisplayName("Display Name"),

WebDescription("Description"),

Category("Configuration Category")]

ECQWP Context Menu limited entries by user permisssions
When we use the ECQWP and a user of the "Viewers" group expand the context menu of one item. The option "Edit Item" appears. It's true that when the "viewer" clicks the "edit option" an error page appears saying that the user haven't got permissions to do that.
 
One of my tasks was delete the entries from the context menu where the user hasn't got permissions. It seems very dificult until I found the "Perm" option in the context menu table. This attribute of the table allows us to delete the not desired entries but this attribute only accept hexadecimal.
 
At this point the only complicated  is getting the permission mask of the user over the listitem selected... easy :)
 

public string PermMask

{

get

{

SPRoleDefinitionBindingCollection roles = ListItem.AllRolesForCurrentUser;

SPBasePermissions auxPerm = SPBasePermissions.EmptyMask;

foreach (SPRoleDefinition role in roles)

{

if ((auxPerm & role.BasePermissions) != role.BasePermissions)

{

auxPerm |= role.BasePermissions;

}

}

return "0x" + ((long)auxPerm).ToString("x");

}

}

So, I had to paste this property in the ListItemWrap.cs, then I had to create a new column in the ContentQueryWithContextMenus.cs called "PermMask" to pass the value to the ECQWPItems.xslt and add this value on the table attribute "Perm".

JavaScript: Defer Execution
 

First introduced by Internet Explorer 4, the defer attribute of the script element is now part of the HTML 4 and XHTML specifications. The defer attribute gives a hint to the browser that the script does not create any content so the browser can optionally defer interpreting the script. This can improve performance by delaying execution of scripts until after the body content is parsed and rendered.

Here's the brief paragraph describing the defer attribute from the HTML 4.01 specification:

When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.

<script src="script.js" type="text/javascript" defer="defer"></script>
via: http://www.websiteoptimization.com/speed/tweak/defer/
 
ECQWP Delete Item Failure!

The problem begun when I downloaded the new version of the ECQWP beta 2.

With this webpart I was unable to delete any list item on the ECQWP list. When I clicked on the "Delete" item of the context menu nothing happens, no message box, no delete list item, nothing.

Ok, I solved this issue coding into the js libraries of the Sharepoint core. I went to "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033\CORE.js" and I override the function "DeleteDocLibItem" placing the new code after the function.

//OVERRIDE FUNCTION BY ALA//

function DeleteDocLibItem(delUrl, isCopy) {

if (!IsContextSet())

return;

var ctx = currentCtx;

var strConfirm = (currentItemFSObjType == 1) ?

(ctx.RecycleBinEnabled ? L_STSRecycleConfirm1_Text : L_STSDelConfirm1_Text) :

(ctx.RecycleBinEnabled ? L_STSRecycleConfirm_Text : L_STSDelConfirm_Text);

if (isCopy && currentItemFSObjType != 1)

strConfirm = L_NotifyThisIsCopy_Text + strConfirm;

if (confirm(strConfirm))

SubmitFormPost(delUrl);

}

//////////////////////////////

Write in the core.js is not a good practice, so, you can follow this rules to create your custom core and add it to your site.

http://blogs.msdn.com/sowmyancs/archive/2008/04/02/customization-of-core-js-file-in-sharepoint.aspx

Then, I went to my site and test again the delete item on the context menu, when I thought everything were gonna right this screenshot appears

mmmm, then I realized that I had to code in the ECQWP code. I downloaded the code from here and I modified some variables.

 

File ListWrap.cs, Property ContextScriptBlock line 79:

I changed the value

"/_vti_bin/owssvr.dll?CS=65001"

, with the value

list.ParentWeb.Url + "/_vti_bin/owssvr.dll?CS=65001"

 

File ListItemWrap.cs, Property ItemUrl line 22:

I changed the code

string serverRelativeUrl = this.ListItem.Web.ServerRelativeUrl;

with this code

string serverRelativeUrl = this.ListItem.Web.Url;

 

And then… Eh Voilà!!!

The implementation of Flags (Enums) using bitwise operators

Defining the Flags:
To start of with, declare an enum to list all the possible flags. Two things are important when declaring the enum. The first thing you will probably notice is the [Flags] attribute. This is necessary in order to indicate that the enumeration should be treated as a set of flags. The second important thing is assigning a value to each of the items in the enum. The first value should be 1, then just double the value for each consecutive item. The integer type in .NET can store up to 32 flags.

[Flags] private enum Buttons : int
{
···Ok = 1, Cancel = 2, Retry = 4, Help = 8
}

Tip: An "All" item could be added to the list of items in the enumeration as follows: All = Ok | Cancel | Retry | Help
 

Setting flags ON:
To set multiple flags, concatenate the desired flags using the bitwise OR symbol "|":

Buttons buttons;
buttons = Buttons.Ok | Buttons.Cancel;


Setting flags OFF:

buttons &= ~Buttons.Cancel;


via: http://dotnet.org.za/kevint/pages/Flags.aspx
 
Contains flag:
 
if ( (buttons & Buttons.Ok) == Buttons.Ok )
{
    return true;
}
 
 
SPBasePermissions in Hex
via: http://www.jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-1-SPBasePermissions-in-Hex2c-Decimal-and-Binary-The-Basics.aspx

 

Permission Name

 

Hex (base 16)

 

Decimal

EmptyMask 0x0000000000000000 0
List and Document permission    
ViewListItems 0x0000000000000001 1
AddListItems 0x0000000000000002 2
EditListItems 0x0000000000000004 4
DeleteListItems 0x0000000000000008 8
ApproveItems 0x0000000000000010 16
OpenItems 0x0000000000000020 32
ViewVersions 0x0000000000000040 64
DeleteVersions 0x0000000000000080 128
CancelCheckout 0x0000000000000100 256
ManagePersonalViews 0x0000000000000200 512
ManageLists 0x0000000000000800 2048
ViewFormPages 0x0000000000001000 4096
Web level permission    
Open 0x0000000000010000 65536
ViewPages 0x0000000000020000 131072
AddAndCustomizePages 0x0000000000040000 262144
ApplyThemeAndBorder 0x0000000000080000 524288
ApplyStyleSheets 0x0000000000100000 1048576
ViewUsageData 0x0000000000200000 2097152
CreateSSCSite 0x0000000000400000 4194314
ManageSubwebs 0x0000000000800000 8388608
CreateGroups 0x0000000001000000 16777216
ManagePermissions 0x0000000002000000 33554432
BrowseDirectories 0x0000000004000000 67108864
BrowseUserInfo 0x0000000008000000 134217728
AddDelPrivateWebParts 0x0000000010000000 268435456
UpdatePersonalWebParts 0x0000000020000000 536870912
ManageWeb 0x0000000040000000 1073741824
UseRemoteAPIs 0x0000002000000000 137438953472
ManageAlerts 0x0000004000000000 274877906944
CreateAlerts 0x0000008000000000 549755813888
EditMyUserInfo 0x0000010000000000 1099511627776
Special Permissions    
EnumeratePermissions 0x4000000000000000 4611686018427387904
FullMask 0x7FFFFFFFFFFFFFFF 9223372036854775807
Permission Name Hex (base 16) Decimal
EmptyMask 0x0000000000000000 0
List and Document permission    
ViewListItems 0x0000000000000001 1
AddListItems 0x0000000000000002 2
EditListItems 0x0000000000000004 4
DeleteListItems 0x0000000000000008 8
ApproveItems 0x0000000000000010 16
OpenItems 0x0000000000000020 32
ViewVersions 0x0000000000000040 64
DeleteVersions 0x0000000000000080 128
CancelCheckout 0x0000000000000100 256
ManagePersonalViews 0x0000000000000200 512
ManageLists 0x0000000000000800 2048
ViewFormPages 0x0000000000001000 4096
Web level permission    
Open 0x0000000000010000 65536
ViewPages 0x0000000000020000 131072
AddAndCustomizePages 0x0000000000040000 262144
ApplyThemeAndBorder 0x0000000000080000 524288
ApplyStyleSheets 0x0000000000100000 1048576
ViewUsageData 0x0000000000200000 2097152
CreateSSCSite 0x0000000000400000 4194314
ManageSubwebs 0x0000000000800000 8388608
CreateGroups 0x0000000001000000 16777216
ManagePermissions 0x0000000002000000 33554432
BrowseDirectories 0x0000000004000000 67108864
BrowseUserInfo 0x0000000008000000 134217728
AddDelPrivateWebParts 0x0000000010000000 268435456
UpdatePersonalWebParts 0x0000000020000000 536870912
ManageWeb 0x0000000040000000 1073741824
UseRemoteAPIs 0x0000002000000000 137438953472
ManageAlerts 0x0000004000000000 274877906944
CreateAlerts 0x0000008000000000 549755813888
EditMyUserInfo 0x0000010000000000 1099511627776
Special Permissions    
EnumeratePermissions 0x4000000000000000 4611686018427387904
FullMask 0x7FFFFFFFFFFFFFFF 9223372036854775807
via: http://www.jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-1-SPBasePermissions-in-Hex2c-Decimal-and-Binary-The-Basics.aspx
Displaying custom data through SharePoint lists

source: http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx

Click along to build this lovely Web Part, taking data directly from a standard .NET DataSet:

SharePoint lists and libraries are great for storing almost everything, but what about if you need to display structured lists in SharePoint where the data is stored elsewhere?  If you use Office SharePoint Server (MOSS), one great feature for this purpose is the Business Data Catalogue.  However, if you only have Windows SharePoint Services (WSS), or need to dynamically construct data, chances are you'll end up needing to write a Web Part.

Web Parts give you some standard look and feel elements for free, like the ‘crome' or border, plus an ability to add your own properties to the properties grid.  After that, you're pretty much on your own.  Wouldn't it be nice if you could display your own data in a sexy SharePoint list?

SharePoint uses the Microsoft.SharePoint.WebControls.SPGridView control to display its own lists.  This class inherits from System.Web.UI.WebControls.GridView, so the development experience to bind data, adjust columns, perform sorting etc is similar.  The key difference is the control renders the grid in the SharePoint style - perfect.

Create a Web Part

Any blank Web Part will do - you could use the template provided by Visual Studio if you have the SharePoint SDK installed.  My web part started out life like this:

using System; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Serialization; using System.Data; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages; namespace ListMenuSample { public class ListMenuSample : System.Web.UI.WebControls.WebParts.WebPart { private SPGridView oGrid; private TVData oDataset; private DataView oView; private void PopulateDataset() { // TODO } protected override void CreateChildControls() { // TODO } void oGrid_Sorting(object sender, GridViewSortEventArgs e) { // TODO } } }

Create the data source

In this example, we'll create and populate a dataset and use it for data binding.  I want a list to keep track of who presents my favourite BBC current affairs programmes, so I'll design and populate a DataSet accordingly.

If you want to bind your SPGridView back to SharePoint data, that's simple too, check out this great article from Share This Point.

My DataSet, TVProgrammeData has a single table, Presenters, comprising an int and two string columns:

We'll fill the DataTable from code, but obviously you'd want to pull this from somewhere, probably SQL, a filesystem, a web service or XML.  Pop this into the PopulateDataset() method.

private void PopulateDataset() { oDataset = new TVData(); oDataset.Presenters.AddPresentersRow(1, "Jeremy Paxman", "Newsnight"); oDataset.Presenters.AddPresentersRow(2, "Kirsty Wark", "Newsnight"); oDataset.Presenters.AddPresentersRow(6, "Bill Turnbull", "Breakfast"); oDataset.Presenters.AddPresentersRow(7, "Sian Williams", "Breakfast"); // plus a few more entries }
 

Render the Grid

Overriding CreateChildControls() is a good place to create your SPGridView and add it to the controls collection.  You'll also need to bind up the columns and specify sorting.  To give us magical sorting abilities, we'll bind to a DataView rather than directly back to the DataTable.  Pop this into CreateChildControls():

protected override void CreateChildControls() { PopulateDataset(); oView = new DataView(oDataset.Presenters); oGrid = new SPGridView(); oGrid.DataSource = oView; oGrid.AutoGenerateColumns = false; oGrid.AllowSorting = true; oGrid.Sorting += new GridViewSortEventHandler(oGrid_Sorting); BoundField colName = new BoundField(); colName.DataField = "PresenterName"; colName.HeaderText = "Presenter Name"; colName.SortExpression = "PresenterName"; oGrid.Columns.Add(colName); // Add the menu control here BoundField colProgramme = new BoundField(); colProgramme.DataField = "ProgrammeName"; colProgramme.HeaderText = "Programme"; colProgramme.SortExpression = "ProgrammeName"; oGrid.Columns.Add(colProgramme); Controls.Add(oGrid); oGrid.DataBind(); base.CreateChildControls(); }

Notice we specify the SortExpression to use, which together with AllowSorting enables users to order the results by clicking the columns headers.  We need to perform the sort ourselves though, through the event handler; and we'll need to keep track of the sort direction in ViewState so we can flip it next time the user clicks the same header.  I'm not sure my code is very elegant in this area, so leave a comment if you can think of a better way to do it in fewer lines of code.

Add this event handler:

void oGrid_Sorting(object sender, GridViewSortEventArgs e) { string lastExpression = ""; if (ViewState["SortExpression"] != null) lastExpression = ViewState["SortExpression"].ToString(); string lastDirection = "asc"; if (ViewState["SortDirection"] != null) lastDirection = ViewState["SortDirection"].ToString(); string newDirection = "asc"; if (e.SortExpression == lastExpression) newDirection = (lastDirection == "asc") ? "desc" : "asc"; ViewState["SortExpression"] = e.SortExpression; ViewState["SortDirection"] = newDirection; oView.Sort = e.SortExpression + " " + newDirection; oGrid.DataBind(); }

If you build and deploy this web part, you should get something like this (see this post for tips on the debugging process):

 

That looks alright, and it will adapt correctly if you apply different style sheets, themes or a new master page.  But it's still not a very rich interface.  How about if you wanted users to edit items, or get more detail.  Umm, better add a menu.

Add a menu

It's worth pointing out about now that the documentation around this area is still in production - so I'm coding with a slight emphasis on experimentation for some of the property values - I'll point you to the official source when it's revised.

Anyway, SPMenuField is the class we need, and combines the roles of controlling the drop-down menu with the basic display work done by BoundField.  Let's replace our boring colName column with a shiny menu that looks like this:

// Replace the Name coloumn with a shiny menu colName.Visible = false; // You could remove colName completely SPMenuField colMenu = new SPMenuField(); colMenu.HeaderText = "Presenter Name"; colMenu.TextFields = "PresenterName"; colMenu.MenuTemplateId = "PresenterListMenu"; colMenu.NavigateUrlFields = "ID,PresenterName"; colMenu.NavigateUrlFormat = "do.aspx?p={0}&q={1}"; colMenu.TokenNameAndValueFields = "EDIT=ID,NAME=PresenterName"; colMenu.SortExpression = "PresenterName"; MenuTemplate presenterListMenu = new MenuTemplate(); presenterListMenu.ID = "PresenterListMenu"; MenuItemTemplate biogMenu = new MenuItemTemplate( "Read Biography", "/_layouts/images/EawfNewUser.gif"); biogMenu.ClientOnClickNavigateUrl = "do.aspx?this=%EDIT%&that=%NAME%"; //entry.ClientOnClickScript = "your javascript here"; presenterListMenu.Controls.Add(biogMenu); MenuItemTemplate broadcastMenu = new MenuItemTemplate( "Recent Broadcasts", "/_layouts/images/ICWM.gif"); presenterListMenu.Controls.Add(broadcastMenu); MenuSeparatorTemplate sepMenu = new MenuSeparatorTemplate(); presenterListMenu.Controls.Add(sepMenu); MenuItemTemplate favMenu = new MenuItemTemplate( "Add to Favorites", "/_layouts/images/addtofavorites.gif"); presenterListMenu.Controls.Add(favMenu); this.Controls.Add(presenterListMenu); oGrid.Columns.Add(colMenu);

Tip: You can have a poke around the standard icon collection and pick some suitable images from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES

SPMenuField serves two purposes - it configures the hyperlink you follow if you click on the item directly and, optionally, links to a snazzy dropdown menu.

This great post at SharePoint Solution Blog gives a good overview of how to extend the Admin interface with custom menus.  However, the difference with custom menus on list items is that you're not creating one - you're creating one for each list item, and your menu handling routine needs to know which item you clicked in.

Fortunately, there are a few ways to achieve with.  First we setup colMenu to pass in the required parameters when you click on the main item hyperlink:

Here, NavigateUrlFields is a comma-separated list of data bound items we want to use in the URL.  Then we replace placeholders starting at {0} with the items in sequence.

Next, we need to decide how to respond to clicks on the drop-down menu.  We have two options here - build a click URL similar to the one above, or use our own javascript.  We might have a third option to do a sexy postback to an event in the code behind, but I can't decipher exactly how to use that yet - keep tuned.

The URL way uses a modification in syntax but essentially the same principle as above.  This time we name the data fields we want and then consume them within % signs on the menu items:

Let's finish off for now by adding some grouping (and a few more presenters):

oGrid.AllowGrouping = true; oGrid.AllowGroupCollapse = true; oGrid.GroupField = "ProgrammeName"; oGrid.GroupDescriptionField = "ProgrammeName"; oGrid.GroupFieldDisplayName = "Programme";
 
 

Leave a comment if you've found this useful, and particularly if there's anything else you'd like to see added.

Enjoy. 

source: http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx

1 - 10 Next

 ‭(Hidden)‬ Admin Links