Sunday, November 9, 2014

[How To?] Set expiration policy for items

Sometime, we've got the stresses to see a warning message from system event viewer. It showed the database limited exceeded or the list is reached the threshold for auditors and administrators but it's not too many items in the list. If you don't want to waste the resources, databases and the time to access the list, there is a way to delete the very old items and think about the deleting process in case.

Microsoft Office SharePoint Server [2010, 2013] has a feature to cover all items following the date and do an action if the condition in criteria reaches out.

Here is a instruction to set the expiration for SharePoint list item

  • Go to Central Administration -> Monitoring -> Review Job Definitions: to make sure that the job named "Expiration Policy" is running.

  • Go to Site Actions -> Site Setting -> Site Content Types under Galleries category. Click on any content type that you want to set the expiration date. This is not applied to specific list/site or item but for content type. 

  • Click on Information management policy settings to enable the Retention option.

  • The Library Document has own the retention settings, if administrator defines the stage in library setting, the setting for document content type will be overwritten. If there are many stages in the setting, make sure that the action and condition in each stage is separately and unique.   
  • In this challenge, I will define a stage to delete very old item. See a picture
  • All items there were created a month ago will be deleted automatically.
  • Of course, we could define many stages for one content type and each of stage can have a repeater actions.
  • It's only available for Microsoft Office SharePoint Server. There is no feature for SharePoint Foundation.
  • We could not define a condition with specific date.
  • It has not supported the query condition instead of selecting on date-time column.
  • There is no exception on the query.
  • There is no configuration for specific list, site or item.

Friday, July 25, 2014

Access denied while the code accessed the property named MyWeb.Navigation.UseShared in SharePoint 2013

I don't know the reason why it took a long time for me to fix the issue in SharePoint 2013. I don't know whether my SharePoint developing skill is down or not and I think I am too old to work as a developer.

My situation is:
Step 1: Backup database of web application in SharePoint 2010
Step 2: Attach this database into SharePoint 2013
Step 3: Upgrade the site

Everything worked correctly accept for the home page throw the error "Access denied". They show "this page is not shared with you!"

The home is inherited the custom master page and using the custom code to add the navigation to top link bar.

This is a code:

            MyWeb.AllowUnsafeUpdates = true;

            if (!MyWeb.IsRootWeb)
                MyWeb.Navigation.UseShared = true;

                if (!MyWeb.ParentWeb.Navigation.UseShared)
                    // Get top link bar.
                    SPNavigationNodeCollection topnav = MyWeb.ParentWeb.Navigation.TopNavigationBar;

                    serverRelativeUrl = MyWeb.ServerRelativeUrl;

                    // Query for an existing link.
                    SPNavigationNode node = topnav
                        .FirstOrDefault(n => n.Url.Equals(serverRelativeUrl));

                    // No link, so add one.
                    if (node == null)
                        // Truncate long a title.
                        string linkTitle = MyWeb.Title;
                        if (linkTitle.Length > 15)
                            linkTitle = linkTitle.Substring(0, 12) + "...";

                        // Create the node.
                        node = new SPNavigationNode(linkTitle, serverRelativeUrl);

                        // Add it.
                        node = topnav.AddAsLast(node);

            MyWeb.AllowUnsafeUpdates = false;

You know what,  the property named "MyWeb.Navigation.UseShared" is only work with Design role assignment or higher. If I logged into site by contributor, it will throw exception "Access denied".

This is error tracking:

System.Threading.ThreadAbortException: Thread was being aborted.   at System.Threading.Thread.AbortInternal()   at System.Threading.Thread.Abort(Object stateInfo)   at System.Web.HttpResponse.AbortCurrentThread()   at Microsoft.SharePoint.Utilities.SPUtility.Redirect(String url, SPRedirectFlags flags, HttpContext context, String queryString)   at Microsoft.SharePoint.Utilities.SPUtility.RedirectToAccessDeniedPage(HttpContext context)   at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(HttpContext context)   at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex)   at Microsoft.SharePoint.SPSecurableObject.CheckPermissions(SPBasePermissions permissionMask)   at Microsoft.SharePoint.SPSecurity.ValidateSecurityOnOperation(SPOperationCode code, SPSecurableObject obj)   at Microsoft.SharePoint.SPSecurityOnOperationScope..ctor(SPOperationCode code, SPSecurableObject obj)   at Microsoft.SharePoint.Navigation.SPNavigation.set_UseShared(Boolean value)   at Bamboo.CommunityCentral.MasterPageBase.<AddCentralSiteToTopLinkBar>b__5()   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3()   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)   at Bamboo.CommunityCentral.MasterPageBase.AddCentralSiteToTopLinkBar()   at Bamboo.CommunityCentral.MasterPageBase.OnLoad(EventArgs e)

Remember: That code cannot work under privileged delegation, thus there is one way to pass the error is to check the current user before apply the code.

Good luck to you.

Monday, July 14, 2014

[Resolved] Error: Unable to get value of the property 'showWaitScreenWithNoClose': object is null or undefined

Today, I will try to use the API with a wide library JS in SharePoint 2013. If you are familiar to JS and SharePoint Client Object Model, you will know how to call a method or execute a query using SharePoint API. However, to work with SharePoint 2013 smoothly, you must research what the SharePoint did!

In some js library, SharePoint had supported a debug file to help you learn to be acquainted with approaching API client library. And I have resolved a great of issues based on that.

My use case is: when I click on a post-back button, after the back-end processed and return the data, the page is reload and I don't want to submit as a post-back re-rendering all view state. The code looks like:

<asp:Button runat="server" Text="Process..." OnClientClick="Update()" OnClick="btn_ProcessClick"></asp:Button>

and the Js code is:

function Update() {
        var dialog = SP.UI.ModalDialog.showWaitScreenWithNoClose("Waiting!", "Processing...");

I did not implement any remaining functions, just need to test a window dialog to ensure the dialog works fine. But the result is:

Error: Unable to get value of the property 'showWaitScreenWithNoClose': object is null or undefined

My though is all client scripts are loaded and SharePoint did by using the default master page. And that's true! However, to initialize the object or class we must ensure the script loaded into page before using. To fix this issue, the code was changed:

var fn = function() {
        var dlg = SP.UI.ModalDialog.showWaitScreenWithNoClose("Waiting!", "Processing...");
var defd;

try {
     defd = typeof SP.UI.ModalDialog.showWaitScreenWithNoClose;
 catch (e) {
        defd = "undefined";
EnsureScript("SP.UI.Dialog.js", defd, fn);

And the result is:

Conclusion: To work with API client SharePoint object model, we must ensure the scripts loaded!

Tuesday, April 15, 2014

Update: How to SharePoint 2013 resolve saving conflict when updating item in Discussion Board

If you are developer and try to update something in the list/site, you will get the error sometime lile this:

Save Conflict
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes

However, SharePoint 2013 has been fixed this issue by using loop statement to save again. Try 5 times to avoid the conflict saving data.
using (new SPMonitoredScope(string.Format(CultureInfo.InvariantCulture, "HandleSaveConflict for method: {0}", new object[] { action.Method.Name })))
        int num = 0;
        while (num < 5)
            catch (SPException exception)
                ULS.SendTraceTag(0x220191, ULSCat.msoulscat_WSS_General, ULSTraceLevel.Verbose, "Save conflict in Discussion update: " + exception.Message);
                if ((num == 5) || !SPUtility.IsSaveConflictException(exception))

That's s cute and funny. But that's fine. Learn from #Microsoft #SharePoint team to update the list somehow. Like it!

Thursday, January 9, 2014

Difference between tracking list in SharePoint 2010 and 2013

SharePoint 2010 has 3 kinds of tracking list: Task, Project Tasks and Issue Tracking. To create one of these lists, just go to Site Action and click on More Options. It doesn’t depend on site template completely. The following table is described details of these lists:

Feature ID
List Template
Project Tasks
Issue Tracking

There is a special option in the Advance Setting: Email Nofitication. This option is enabled if the Email Setting in Central Administration has been configured. When this option is set to ‘Yes’, that means the user who has been assigned to by ownership will get the alert by email or the ownership has changed something in that item.

Before to enable Email Notification option, take a look at Item-level Permissions options. To manage user working on the list, the moderator could change this option to allow/disallow user who has permission to read, edit or doing something on list item.
Assume that the user who has not permission to read the item but was assigned by the owner. So, what will happen and how the user could see that item? If you are still feel confused, let see the WAD of SharePoint 2013.
SharePoint 2013 has exposed much more tracking list: Tasks, Task /w. timeline, Issue tracking and GanttTasks. GanttTasks is actually a project tasks in SharePoint 2010 and after exposed with more Tasks /w. timeline then this list to be the default tasks.
Feature ID
List Template
Tasks /w. timeline
Issue Tracking

In the site contents to add a new app, SharePoint 2013 was hidden Tasks (107) and GanttTasks (150). And except for Task with timeline doesn’t have an option Email Notification, all the others tracking list have this option. Thus, if you try to enable this option by programmatically, the alert by email still doesn’t work or work incorrectly.
In sharePoint 2013, to create the hidden list, please change the url and go:
Where: FEATURE_ID is a feature id to work with that list, and LIST_TPL_ID is a list template id.

Friday, January 3, 2014

Announcement: SharePoint Saturday Event 7th & resume SharePointVietNam.NET forum

SharePoint Saturday Vietnam (SPSVN) is a free community focused SharePoint event dedicated to educating and engaging members of the local technical community. SPSVN draws upon the expertise of local SharePoint IT professionals, developers, and solution architects who come to together to share their real world experiences, lessons learns, best practices, and general knowledge with other like minded individuals.

SPS VN 7th will be held on Saturday, Jan 11th, 2014. The agenda and information you will find on

Location of SPS VN 7th

For SPS Vietnam, I was speaking at the event with some topics to help developers and administrators work with the best practice:

  • 1st: All about the Ribbon of SharePoint 2010
  • 4st: The Best Practice SharePoint Developing
  • 5th: The Best Practice SharePoint Farm Installation
  • 6th: Improve performance and security with best practice for SharePoint WP/App

In 2014,  I will share a lot of articles about SharePoint 2013 apps for developing with trying my best. In the community, I also try to join the SPS VN discussing about the growing SharePoint apps in VN and then resume the forum for all Vietnamese SharePointers. If you have any question or something good idea you could share in the forum. This forum is a free community and don't hesitate posting on that. I (and another people) will follow and reply as soon as possible.

Thursday, January 2, 2014

Could not run the SharePoint Wizard Configuration after install the hotfix?!

SharePoint 2013 takes so long time to install and configure the CU hotfix, it took more than 5 hours for me to install. I actually increase the RAM to 16GB but the problem is not improved and more and more longer than usual. Eventually, you do not need to install the CU hotfix for August 2013, just install March, October and December 2013. That's all. If you still feel unconvinced with the duration of installing, you could see to stop the service and run the PS command as link helping bellow:

Somebody thought that could be install all the hotfix then after all run the wizard configuration, of course could do something like that, but at the end the error will happen if you run the SharePoint Wizard Configuration:

Don't worry about that, just do it as your best and do not need to run the wizard as normally. Just run the command by command line:

psconfig.exe -cmd upgrade -inplace b2b -force -cmd installcheck -noinstallcheck

Here is the blog to explain about the above command: