Monday, November 9, 2009

You wanna handle page content based on Permissions..!!!.. Tell me....

To start with this post implementation one needs to have a little less known built in XSLT function called ddwrt:IfHasRights()) and some Conditional Formatting logic.
Simply select the text or mark-up inside the data view web part and then
Click on Conditional Formatting option in the Task Panes menu
In the Condition Criteria dialog box select Advanced and in the Advanced Condition dialog box change Select a function category to All
Find and insert the IfHasRights() function by double clicking on the Select a function list
Use a single Permission Mask for example 4 IfHasRights(4) to only make the mark-up or text visible when the user has edit rights on the page\item
Following is a list of Permission Masks for the build in permissions
1. ViewListItems – 1
2. AddListItems – 2
3. EditListItems – 4
4. DeleteListItems – 8
5. ApproveItems – 16
6. OpenItems – 32
7. ViewVersions – 64
8. DeleteVersions – 128
9. CancelCheckout – 256
10. PersonalViews – 512
11. ManageLists – 2048
12. ViewFormPages – 4096
13. Open – 65536
14. ViewPages – 131072
15. AddAndCustomizePages – 262144
16. ApplyThemeAndBorder – 524288
17. ApplyStyleSheets – 1048576
18. ViewUsageData – 2097152
19. CreateSSCSite – 4194314
20. ManageSubwebs – 8388608
21. CreateGroups – 16777216
22. ManagePermissions – 33554432
23. BrowseDirectories – 67108864
24. BrowseUserInfo – 134217728
25. AddDelPrivateWebParts – 268435456
26. UpdatePersonalWebParts – 536870912
27. ManageWeb – 1073741824
28. UseRemoteAPIs – 137438953472
29. ManageAlerts – 274877906944
30. CreateAlerts – 549755813888
31. EditMyUserInfo – 1099511627776
32. EnumeratePermissions – 4611686018427387904
33. FullMask – 9223372036854775807

For example,



Another approach for the same problem set is as follows :

<SharePoint:SPSecurityTrimmedControl ID=”SPSecurityTrimmedControlName″ PermissionsString=”” runat=”server”>

The markup that needs to be security trimmed goes here.

</SharePoint:SPSecurityTrimmedControl>
The above mentioned permissions acan be used as trimmer parameter (you can add multiple using commas).

Tuesday, June 9, 2009

Content Editor Web Part Magic - 1 : Add Outlook Inbox on web page using Content Editor Web Part

A lot has been talked about the fascinating features of Content Editor Web Part (CEWP) in MOSS 2007. Have you thought about its features like get your java script added on the share point page and do whatever you like (if attainable in java script!!) or have your mind horses galloped to the field to get your Outlook configured on the web page with a blazingly accountable performance. I have said this because already there are OOB web parts available to drag items from you Outlook account and get them stitched on your web page. But going that way may be too much costly in terms of performance (the most important thing for you clients..!!. No doubt every lacking thing from your side is on priority of client’s wish list!!).
So cutting the crap now and coming to the point: Using java script to yank the items from your Outlook account and get them travel to your web page is as simple as reading this blog. So for your convenience (prime concern for this blog owner), I have summarized the steps as below:
· Add a new web part page in your share point site, say Outlook.aspx.
· Edit the page and add a CEWP on to that.
· Edit the CEWP using the Edità Modify this web part sort of thing.
· Open the Source Editor window by bashing the “Source Editor…“ guy there.
· Okay the billion dollar point, Add the below code in the window and Save.

< language="javascript" type="text/javascript">

function getNewEmail() {

try {

o = new
ActiveXObject("Outlook.Application");

if(o) {

mailFolder =
o.getNameSpace("MAPI").getDefaultFolder(6);

//You could also use custom forms like
//IPM.Note.CustomForm

mailItem = mailFolder.Items.add("IPM.Note");
mailItem.Display(0);

}

}

catch(e) {

window.status = e.Message;

}

}

< /script>

< type="button" title="Send new email" value="New" onclick="javascript:getNewEmail();">

< classid="CLSID:0006F063-0000-0000-C000-000000000046" width="100%"> < name="Folder" value="Inbox"> < /OBJECT>

< classid="CLSID:0006F063-0000-0000-C000-000000000046" width="100%"> < name="Folder" value="Tasks"> < /OBJECT>

· Now close your eyes and count to 3…!!! .
· Open your eyes and see what you have done..!!!??. The “Inbox” and “Tasks” are welcoming you on your web page.
· Control your ecstasy and Click OK there in the right hand side.
· If this is a Publishing Page, publish it or if it is a team site, then Exit edit mode.
· Wooo... hoooo… TADAAAA….!!!. You can see the “Inbox”, “Tasks” have been fetched from your Outlook account and are served to you on your page..!! What a mind blowing job you have done…. ??
· OK... do you see something else there? A poor guy... a “New” button?? Don’t get confused... it is there because of you… and for you.. Since this activity is not able to provide you everything that an OOB web part can but yes it gives you at least some hold to you to have done your customizations.
· So that’s all form me... what else are you waiting for??? Go and play with your Outlook now…!!
You rock…!!!


Friday, May 22, 2009

Pre compile your website and publish it without source code or markup

  • Brief introduction to building versus pre compiling
    If you build your web application in Visual Studio you'll get at least a few binaries, or .dll, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is requested for the first time after restart. Unless you deploy your web application in a precompiled state that is!
  • Pre compile your web application before deployment
    When you precompile your web application the following takes place:
    1. All markup files (.aspx) are stripped of their content
    2. All web service files (.asmx) are stripped of their content
    3. All code-behind files (.cs) are removed
    4. All user control files (.ascx) are removed
    ...and some other things
    This means that you will be able to deploy your website entirely without readable markup or source code.
    You still need all the markup files in the correct places, but they will no longer contain any actual markup. So, in the future you won't have to worry about updating .aspx files - unless new ones have been added to the web application.
  • How to pre compile your website
    In order to pre compile your web application you need to use a simple command prompt command. If you wanted you could add this command to a post-build event to automate the process.
    The pre compilation is carried out by the aspnet_compiler executable located in your .NET installation folder. If you run the Visual Studio command prompt you won't have to worry about that though - the path variable is then set so that you can execute the aspnet_compiler executable regardless of what folder you are in.
    If you use the standard command prompt (cmd) you'll have to switch to the correct .NET installation folder, for example:
    > c: > cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

    So, let's say I have a website located in C:\MyWebSite. In order to precompile this website I use aspnet_compiler and specify a target folder for the precompiled output:
    > aspnet_compiler -p C:\MyWebsite -v / C:\MyPrecompiledWebsite
    The C:\MyPrecompiledWebsite will now contain a precompiled version of the web application. All markup and web service files will now be empty except for a text saying (my emphasis): "This is a marker file generated by the precompilation tool, and should not be deleted!"
    You are now ready to deploy!
  • Additional information
    For more information on different precompilation scenarios and techniques, see:
    ASP.NET Precompilation Overview
    How to: Precompile ASP.NET Web Sites
    How to: Precompile ASP.NET Web Sites for Deployment

Please make a note that this type of deployments are really impressive in scenarios where the site is finally ready to move on your production environment and the modifications are not so frequent on you web site. Also, another case may be if you don't really want to give your code to the client ;).

Tuesday, May 19, 2009

Custom List Paging in OOB way

using (SPSite mySite = new SPSite("site url"))
{
using (SPWeb myWeb = mySite.OpenWeb())
{
SPList myList = myWeb.Lists["List Name"];
if (myList != null)
{
SPQuery myQuery = new SPQuery();

myQuery.Query = "";

myQuery.RowLimit = 10;

// Set the paging information with query object in case it is required.
string strPageInfo = string.Empty;

// Prepare the pageInfo string for Previous Page.
if (strEvent == "PREVIOUSPAGE")
{
strPageInfo = "Paged=TRUE&PagedPrev=TRUE&p_" + strSortFieldName + "=" + strSortFieldLastValue + "&p_ID=" + strPageID;
myQuery.ListItemCollectionPosition = new SPListItemCollectionPosition(strPageInfo);
}
// Prepare the pageInfo string for Next Page.
else if (strEvent == "NEXTPAGE")
{
strPageInfo = "Paged=TRUE&p_" + strSortFieldName + "=" + strSortFieldLastValue + "&p_ID=" + strPageID;
myQuery.ListItemCollectionPosition = new SPListItemCollectionPosition(strPageInfo);
}

SPListItemCollection myItems = myList.GetItems(myQuery);
if (myItems != null)
{
// Gets the result set
DataTable dtResult = myItems.GetDataTable();
}
myQuery = null;
myList = null;
}
}
}

Notes:
· strEvent (string) – variable that indicates which event is reuiured “NEXTPAGE” or “PREVIOUSPAGE”.
· strSortFieldName (string) – The list field name based on which sorting is required.
· strSortFieldLastValue (string) – The sorting list field’s value corresponding to the last row being displayed at your UI (eg. GridView).
· strPageID (string) – The list field “ID” value for the last item on UI (eg. GridView).
· isAscending (string) – “true” or “false”, indicates the order of sorting.