Subscribe: SharePoint SharePoint SharePoint

Saturday, July 6, 2013

Delete a list in sharepoint 2010 using powershell

Deleting a list through UI is sometimes a hectic job when your server is slow, so a better approach is to delete the list using powershell. This method is much faster and reliable :

$site = Get-SPSite <Site Collection Name>
$web= $site.openweb()
$lists = $web.Lists
$getList = $web.lists["ListName"]
$getList.Delete()

NOTE : Replace <Site Collection Name> with your current Site Collection Name.
            : You should have required access over ContentDB to delete the list using powershell.

How to get current user displayname with javascript in sharepoint ?

If you need to retrieve the name of the current logged in user in sharepoint , it can be easily done with the help of a ECMA script. Following code illustrates the same : 

<script type=”text/javascript”>
ExecuteOrDelayUntilScriptLoaded(getDisplayName,”sp.js”);
var currentUser;
function getDisplayName(){
this.clientContext = new SP.ClientContext.get_current();
this.oWeb = clientContext.get_web();
currentUser = this.oWeb.get_currentUser();
this.clientContext.load(currentUser);
this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
}

function onQuerySucceeded() {
alert( currentUser.get_loginName());
}

function onQueryFailed(sender, args) {
alert(‘Request failed. \nError: ‘ + args.get_message() + ‘\nStackTrace: ‘ + args.get_stackTrace());
}
< /script>

Friday, July 5, 2013

Content Editor Web Part script error

Many a times when we add a ECMA script to a CEWP, it does not work as expected. This mainly happens because CEWP does not start a server thread. ECMA script can only be executed when a server thread or worker process is associated to it. So in order to make it work, we need to add a function i.e. "ExecuteOrDelayUntilScriptLoaded". It first loads the "SP.js" file so that it can start a server thread.

SharePoint 2010


After loading the "SP.js" file , the ECMA script in the CEWP is executed without any error.

Following is the code depicting the same :