Difference between Security Context of Workflow Code in SharePoint 2007 and 2010
In SharePoint 2010, any code which executes because of the changes made by the workflow process will run in context of the user who either started the workflow or responsible for changes which caused the code to be executed.
But …
In SharePoint 2007, any code which executes because of the changes made by the workflow process will always run in context of SharePoint\System.
Due to the above difference, your SharePoint 2007 code will be able to perform anything on your Site as it will always have Full Permissions whereas in SharePoint 2010, it will depend on the user permission. If you are porting your code from 2007 to 2010 and will need full permission then you should consider using SPSecurity.RunWithElevatedPrivileges method. For details on it, click here
Ideal list of tools you need for SharePoint Development
After working with several clients, I have compiled a list of tools, addons, plugins and technologies which are needed for development, customization or administration of SharePoint. This list is not a “Mandatory Tools List” but in fact, it is a compilation of tools and technologies which can be used at any point in time depending on your role. I will keep extending this list.
Please feel free to suggest more:
Infrastructure
- VMWare Workstation
- Windows 2008 R2
- SQL Server 2008
- Team Foundation Server 2010
Development
- Visual Studio 2010 Professional / Ultimate / Premium
- SharePoint Designer 2010
- Visio 2010
- Infopath 2010
- Fiddler
- Nintex Workflow
- K2 Workflow
- AgilePoint Workflow
- Bamboo WebParts
- Microsoft Expression Studio
- Telerik Controls
- Infragistics Controls
- SharePoint Manager (Codeplex)
- ULS Log Viewer (Codeplex)
- CKSDev (Codeplex)
- .NET Reflector or
- JustDecompile (Free from Telerik)
- Notepad++
- Firebug
End User Tools
- Colligo Contributor Pro
Graphics Designing
- Photoshop
- GIMP
Administration
- PowerShell
- Axceler’s ControlPoint
- AvePoint Products
Training:
- Global knowledge http://www.globalknowledge.ca/training/course.asp?pageid=64&courseid=12991&catid=213)
Learning Resources:
- SharePoint Developer Center (MSDN) http://msdn.microsoft.com/en-us/sharepoint/aa905688
- SharePoint StackExchange http://sharepoint.stackexchange.com/
Solution for viewing HTML files in browser from SharePoint Document Library
In SharePoint 2010 document library, if you click on a file with .html extension, you will notice that browser will open Save File dialogue box. This behaviour stops you to view HTML files directly in browser from document library and some times it is very annoying.
To resolve it and view HTML files in browser, here are the steps:
- Open SharePoint Central Administration
- Click Application Management
- Under Web Applications, click Manage web applications
- Click on your target web application to select it
- On ribbon, click on Web Application tab
- Open General Settings menu and click on General Settings
- Scroll to Browser File Handling and change it from Strict to Permissive
- Click OK to save your changes
- Thats it!
Now, go back and try to view HTML file, browser will display it. Enjoy!
Correct way of generating Source parameter value in your SharePoint Link
As you may already know that SharePoint uses Source parameter in query string to take you back to the page from where you came.
The value of the Source paramter must be properly encoded. Don’t worry, you do not need to write your own Javascript function to do this. Just use already provided function called
GetSource(defaultSource)
It will return you properly encoded string to pass as Source parameter value. Following is the logic inside this function:
- Try to retrieve the value Source parameter from current query string.
- if Source parameter found then return it by properly encoding and making sure it is safe to navigate.
- If there is no Source parameter in Query string then
- Check if defaultSource has a non empty value,
- if yes then return it by properly encoding and making sure it is safe to navigate.
- Otherwise, return the current page url by properly encoding and making sure it is safe to navigate.
Useful Javascript Functions and objects in SharePoint – Part 2
- byid(id) = Return element for the given id
- newE(tag) = Create a new dom element of the given tag e.g. div etc.
- wpf() = return ASP.net form object for the current web part page
- GetEventSrcElement(e) = return source element for the given event object
- GetEventKeyCode(e) = Return key code of the currently pressed key for the given object
- GetInnerText(e) = Return inner html for the given object
HTML Encoding and Decoding
- escapeProperlyCoreCore(str, bAsUrl, bForFilterQuery, bForCallback) = Very useful function to perform any type of string escaping. Last three parameters are flags to perform deifferent type of escaping i.e.
- bAsUrl = true, for url escaping
- bForFilterQuery = true, for filter query escaping
- bForCallback = true, for call back escaping
- escapeProperly(str) = Escapes the given string to make it valid SharePoint compatible string. It internally calls escapeProperlyCoreCore to perform the actual escaping
- escapeUrlForCallback(str) = Escapes the given string to make it valid url for call back
- encodeScriptQuote(str) = Replace the apostrophe i.e. ‘ to %27 in the given string
- STSHtmlEncode(str) = Encodes the reserved characters to their respective HTML entities in the given string. For example “<div>” will become <div>
- StAttrQuote(st) = Encodes the “&”, “ “ ” and carriage return to their respective HTML entities in the given string.
- STSScriptEncode(str) = Encodes the given string for use in script. It has the same functionality as SPEncode.ScriptEncode defined here
- STSScriptEncodeWithQuote = Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser, and writes the string in quotation marks
- escapeForSync(str) = Encodes the given string for syncing. Need further clarification.
- Vutf8ToUnicode(rgBytes) = Converts the given utf8 string to unicode
- unescapeProperly(str) = Unescapes the given escaped string
Validations
- PageUrlValidation(url) = Checks if the given string is a valid url or not.
- IndexOfIllegalCharInUrlLeafName(strLeafName) = Return the index of character in the given string which is illegal to be used in url leaf name.
- IndexOfIllegalCharInUrlPath(strPath) = Return the index of character in the given string which is illegal to be used in url leaf name.
- UrlContainsIllegalStrings(strPath) = Returns true if the given string contains an illegal character which can not be used in a url. Otherwise, return false.
- UrlLeafNameValidate(source, args) = Validates the url leaf name. Returns true if valid otherwise, false. Need further clarification.
- UrlPathValidate (source, args) = Validates the url path. Returns true if valid otherwise, false. Need further clarification.
- IsCheckBoxListSelected(checkboxlist) = Returns true, if the given checkbox is either null or at least one check box is checked in it.
- IsAccessibilityFeatureEnabled() = Returns true, if the accessibility feature is enabled by checking the cookie called “WSS_AccessibilityFeature”
Cookie Management
- DeleteCookie(sName) = Deletes the given cookie by setting its expiry date to 01-Jan-1970
- GetCookie(sName) = Returns the given cookie
Navigation
- navigateMailToLink(strUrl, strUrlNew) = Creates a mail to link for the given url
- GetUrlFromWebUrlAndWebRelativeUrl(webUrl, webRelativeUrl) = Creates a url by combining webUrl and relative url. It takes care of checking null webUrl and slash character at the end.
Syncing with other applications
- GetStssyncAppNameForType(strType,strDefault) = Returns an string similar to “Connect to Outlook” etc. depending on the given type.
- GetStssyncIconPath(strDefault, strPrefix) = Returns the path of icon image for the given syncing application type.
- ExportHailStorm ( ….. ) = Creates connection to Outlook. Check here for further details.
Miscellaneous
- DeferCall() = Not sure.
- AdmBuildParam(stPattern) = Not sure.
To be continued….
Useful Javascript Functions and objects in SharePoint – Part 1
SharePoint has a huge set of javascript functions and objects which are defined in essential SharePoint javascript files like init.js, core.js, forms.js etc. These files are necessary for SharePoint to function properly. There is no reason to reinvent the wheel by writing your own javascript function for something which is already provided by these core javascript files.
I will run a series of articles to list down necessary objects and functions provided by SharePoint. I hope you will find them useful.
Useful Objects
JSRequest : It is a global object which is used to get information about current page. It has following properties:
- QueryString : An array of Querystring key and values,
- FileName : Name of the current file e.g. default.aspx
- PathName : current path of the page
NOTE: Before using this object properties, always call JSRequest.Ensuresetup()
L_Menu_BaseUrl : Relative path for current site. e.g. “/TestSite”. It is useful to construct web relative paths for ajax calls of web services etc.
L_Menu_LCID : Current culture Id e.g. “1033″ for US English. It is useful to retrieve culture specific files, if need.
L_Menu_SiteTheme : Current site theme name e.g. Lacquer. If no theme is applied then it will be empty.
browseris : This object has several properties to detect browser name, major and minor version, operating system version etc. For example, if you want to know whether the current browser is IE or not then check browseris.ie. If it is true then IE else others. To get full details of its properties, use FireBug.
LegalUrlChars : Array of all characters which are allowed in Url for SharePoint.
_spBodyOnLoadFunctionNames : Array of javascript function names to be executed just after DOM is fully loaded. If you want to execute any of your function once the page is fully loaded then add your function name in this array. For example _spBodyOnLoadFunctionNames.push(“MyFunction”);
_spUserId : User Id of the currently logged in user. It is an integer e.g. 1. You can use this value perform any logic against a currently logged in user.
ctx or ctx1 or ctx2 … etc. There can be many ctx objects in a single page. These objects are instances of ContextInfo class. They are used to provide user context information necessary to create Edit Control Block menu items. Please use FireBug to see the list of all properties available. Visit here for more info
g_ExtensionDefaultForRead : An array of file extension strings which are always checked out as Read only. For example, jpg, jpeg, bmp etc.
g_ExtensionNotSupportCheckoutToLocal : An array of file extension strings which are not allowed to checkout locally. For example, aspx, ascx, cmd etc.
Check my next post for available Javascript functions.
Quickest way to create Slide Show from your Picture Library in SharePoint
Although there are many scripts available on internet which helps you to create slide show or image carousel but none of them gives us the ability to display Title and Description along with the image. I searched quite a lot and then ultimately end up creating my own.
I must clarify that I have not written the entire code myself. What I have done is to use the following already available JavaScript libraries and then assemble them in a way which gives us a quickest way to create image carousel from SharePoint Picture Library:
Enough talk, now lets come to the point:)
Step 1: Plugin Setup
- Download the Easy Slider Plugin from http://cssglobe.com/lab/easyslider1.7/easyslider1.7.zip
- Unzip the file and Upload easySlider1.7.js to a document library.
Step 2: Note down the List ID
- Navigate to your Site Actions -> Site Settings
- Under Site Administration, click Site libraries and lists
- Click on your Picture Library name, to open it.
- Note down the value of parameter List as displayed in Url window of your Internet explorer. It will be something like {26EC0E08-3D8A-4C67-ABF5-909D572B3030}
- Add a content editor web part (CEWP) on your target page
Step 3: Set up Content Editor Web Part
- On your target page, add a content editor web part (CEWP)
- Paste the following code in Source Editor
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- Step 1: Download easy slider plugin fromhttp://cssglobe.com/lab/easyslider1.7/easyslider1.7.zip -->
<script type="text/javascript" src="http://TestServer/TestSite/js/easySlider.js"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("startSlider");
function startSlider() {
//Step 2 Replace {26EC0E08-3D8A-4C67-ABF5-909D572B3030} with the ID of your picture library
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>{26EC0E08-3D8A-4C67-ABF5-909D572B3030}</listName> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "//"+window.location.hostname+L_Menu_BaseUrl+"/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
};
function processResult(xData, status) {
//Uncomment the following line to see the raw xml received from lists.asmx
//$("#rawXml").text(xData.responseText);
$(xData.responseXML).find("z\\:row").each(function() {
//Get relevant field values
imageUrl="//"+window.location.hostname + "/" + $(this).attr("ows_FileRef").split(";#")[1];
var description=getDescription( $(this).attr("ows_MetaInfo"));
var title=$(this).attr("ows_Title");
//Construct required HTML Markup
var liHtml = "<li><h3>" + title + "</h3>" ;
liHtml+="<IMG border=0 alt='" + title + "'src='" + imageUrl + "' >";
liHtml+="<p>" + description + "</p>";
liHtml+="</li>";
//Add markup as line item in UL tag
$("#imagesUL").append(liHtml);
});
//Start Slider
//For full options, refer to http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
$("#slider").easySlider({
auto: true,
continuous: true,
controlsShow : false,
speed : 800,
pause : 4000
});
}
function getDescription(metaInfo)
{
var description="";
if(metaInfo!=null)
{
metaParts=metaInfo.split("\n");
if(metaParts!=null && metaParts.length>0)
{
var i=0;
do
{
if(metaParts[i].indexOf("vti_description")>-1)
{
var descParts=metaParts[i].split("|");
if(descParts!=null && descParts.length>1)
{
description=descParts[1];
}
}
i++;
} while (i<metaParts.length && description=="" );
}
}
return description;
}
</script>
<style type="text/css">
#slider{border-bottom:2px solid #ccc; background:#eee; padding:5px; font-size:x-small;}
#slider h5{font:italic medium Georgia, Times, serif; color:#555; padding:3px; margin-bottom:-10px; background:#c6c6c6;}
#slider h5 span{text-transform:lowercase; padding:5px; font:x-small normal Arial, Helvetica, san-serif;}
#slider div {font-size: x-small; padding:3px;}
#slider ul, #slider li{margin:0; padding:0; list-style:none;}
#slider li{width:310; height:400px; overflow:hidden; padding:0px;}
#controls2 {padding:3px 0 0 0; text-align:right; width:300;}
#prevBtn, #nextBtn{}
#nextBtn{}
#prevBtn a, #nextBtn a{font-size:x-small; background-color:#ccc; color:#444; padding:2px; text-decoration:none;}
#nextBtn a{}
</style>
<div id="rawXml" ></div>
<div id="slider">
<ul id="imagesUL"/>
</div>
Step 4: Update Code
- Replace {26EC0E08-3D8A-4C67-ABF5-909D572B3030} by the List ID you got in step 2, above
- Click OK, exit edit mode and Enjoy!
Notes:
- This code is a sample code and you may need to change the styles section to match your site’s theme.
- Please make sure all your images are of same size, if not, then please adjust the size in line 47 of source code.
- This code assumes the size of images as 300×300 pixels, if you need to change it then update the relevant size at line 98.
All credits goes to JQuery and easy slider plugin
List of SharePoint Base Permissions with their Hex and Decimal Values
Here is the list of all SharePoint base permissions valid for Windows SharePoint Services and SharePoint Foundation both, along with their Hex and decimal values. I hope it will help you to easily reference them in your projects.
|
Permission Name |
Hex Value |
Decimal Value |
Description |
|
AddAndCustomizePages |
0×40000 |
262144 |
Add, change, or delete HTML pages or Web Part Pages, and edit |
|
AddDelPrivateWebParts |
0×10000000 |
268435456 |
Add or remove personal Web Parts on a Web Part Page. |
|
AddListItems |
0×2 |
2 |
Add items to lists, add documents to document libraries, and add |
|
ApplyStyleSheets |
0×100000 |
1048576 |
Apply a style sheet (.css file) to the Web site. |
|
ApplyThemeAndBorder |
0×80000 |
524288 |
Apply a theme or borders to the entire Web site. |
|
ApproveItems |
0×10 |
16 |
Approve a minor version of a list item or document. |
|
BrowseDirectories |
0×4000000 |
67108864 |
Enumerate files and folders in a Web site using Microsoft Office |
|
BrowseUserInfo |
0×8000000 |
134217728 |
View information about users of the Web site. |
|
CancelCheckout |
0×100 |
256 |
Discard or check in a document which is checked out to another |
|
CreateAlerts |
0×8000000000 |
549755813888 |
Create e-mail alerts. |
|
CreateGroups |
0×1000000 |
16777216 |
Create a group of users that can be used anywhere within the |
|
CreateSSCSite |
0×400000 |
4194304 |
Create a Web site using Self-Service Site Creation.
NOTE: CreateSSCSite (0×400000) is a hidden base permission. It is not |
|
DeleteListItems |
0×8 |
8 |
Delete items from a list, documents from a document library, and |
|
DeleteVersions |
0×80 |
128 |
Delete past versions of a list item or document. |
|
EditListItems |
0×4 |
4 |
Edit items in lists, edit documents in document libraries, edit |
|
EditMyUserInfo |
0×10000000000 |
1099511627776 |
Allows a user to change his or her user information, such as |
|
EmptyMask |
0 |
0×0 |
Has no permissions on the Web site. Not available through the |
|
EnumeratePermissions |
0×4000000000000000 |
4611686018427380000 |
Enumerate permissions on the Web site, list, folder, document, |
|
FullMask |
0x7fffffffffffffff |
9223372036854770000 |
Has all permissions on the Web site. Not available through the |
|
ManageAlerts |
0×4000000000 |
274877906944 |
Manage alerts for all users of the Web site. |
|
ManageLists |
0×800 |
2048 |
Create and delete lists, add or remove columns in a list, and |
|
ManagePermissions |
0×2000000 |
33554432 |
Create and change permission levels on the Web site and assign |
|
ManagePersonalViews |
0×200 |
512 |
Create, change, and delete personal views of lists. |
|
ManageSubwebs |
0×800000 |
8388608 |
Create subsites such as team sites, Meeting Workspace sites, and |
|
ManageWeb |
0×40000000 |
1073741824 |
Grant the ability to perform all administration tasks for the |
|
Open |
0×10000 |
65536 |
Allow users to open a Web site, list, or folder to access items |
|
OpenItems |
0×20 |
32 |
View the source of documents with server-side file handlers. |
|
UpdatePersonalWebParts |
s 0×20000000 |
536870912 |
Update Web Parts to display personalized information. |
|
UseClientIntegration |
0×1000000000 |
68719476736 |
Use features that launch client applications; otherwise, users |
|
UseRemoteAPIs |
0×2000000000 |
137438953472 |
Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 |
|
ViewFormPages |
0×1000 |
4096 |
View forms, views, and application pages, and enumerate lists. |
|
ViewListItems |
0×1 |
1 |
View items in lists, documents in document libraries, and view |
|
ViewPages |
0×20000 |
131072 |
View pages in a Web site. |
|
ViewUsageData |
0×200000 |
2097152 |
View reports on Web site usage. |
|
ViewVersions |
0×40 |
64 |
View past versions of a list item or document. |
What is the meaning of “Limited Access” in SharePoint?
If you are wondering what is “Limited Access” in SharePoint and how does it affect you then here is the simple explanation:
“Limited Access” in SharePoint means a user has an access to an item of the page specifically but not the whole SharePoint list. Normally, we don’t manage individual item permissions and list items normally inherit their permissions from their parent list but sometimes you may need to share a document or a an item to another user who does not have access to the parent list of that item. In this case, you will break the inheritance for that item/document and give permission specifically to that item/document.
Now, since that document resides under its parent library therefore, user will automatically get the “Limited Access” to the parent list which will in turn allow the user to only access that specific document.
For more information, I will recommend you to read Michael Nemtsev article here
Continuous Integration of SharePoint Project by using TFS
SharePoint projects are some what special in the way they use assemblies and some time it is very difficult to setup your TFS build process for continuous integration. Today, SharePoint Developer Team has published an excellent step-by-step process to properly setup your TFS Build Process for SharePoint Projects. You can read the article here
This article guides about the following:
- How to configure the build server to properly compile the SharePoint projects?
- List of necessary SharePoint assemblies to make sure compilation succeeds.
- How to update Powershell script to add the required files on Build server?
- Steps to create build definition.
- How to setup build workflow?
I would highly recommend you to read this article before embarking on your next SharePoint project.

