Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

Sunday, March 27, 2011

Iterative Development Creates a Ton of Unwanted web.config Backup Files

Whenever SharePoint modifies the web.config file, it creates a backup copy with a BAK extension as shown in figure below:

image

These backup files can be helpful on the occasion a previous version of the web.config is needed. However, when you deploy SharePoint assets using MS Visual Studio for iterative development, they can accumulate a ton of unwanted files.

The following steps teach you how to run DOS command after each successful deployment will keep the web application IIS home directory much tidier.

  • Select the SharePoint node, as shown in figure below:

image

  • Type the following into the “Post-deployment Command Line” textbox:

DEL C:\inetpub\wwwroot\wss\VirtualDirectories\[WebApplicationHomeDirectory]\*.bak

Replace [WebApplicationHomeDirectory] with the actual file system directory that IIS refers to as the web application’s home directory.

  • Just below the Post-deployment Command Line, verify that the Default option is selected in the Active Deployment Configuration drop-down.

Saturday, March 12, 2011

Visual Studio 2010 Service Pack 1 is Now Available

Yes, Visual Studio 2010 Service Pack 1 has been released this week. Don’t forget to download and install – get the download from here: Microsoft Visual Studio 2010 Service Pack 1 (Installer).

Friday, March 4, 2011

Cumulative Updates for MOSS 2007, WSS 3.0, SharePoint 2010 has been released

Yesterday Microsoft released the Full Server Packages for February 2011 Cumulative Updates for MOSS 2007, WSS 3.0, SharePoint 2010. KB articles can be found here:

  • KB 2475886 - WSS 3.0
  • KB 2475885 - MOSS 2007
  • KB 2475880 - SharePoint Foundation 2010
  • KB 2475878 - SharePoint Server 2010
  • KB 2475879 - SharePoint Server 2010 with Project Server

February 2011 Cumulative Updates can be downloaded here:

Tuesday, February 22, 2011

Visual Studio Productivity Tool–Latest Update Released

Today Microsoft has released latest update to Visual Studio Productivity Tools. This update includes many improvements, if you like to know more about it, read the following blogs:

Enjoy it!!

Visual Studio is SIMPLY THE BEST!!!

Thursday, February 3, 2011

Windows Phone Training Kit Update Released

The Windows Phone Training Kit has been released today which includes few new labs – you can download Windows Phone 7 Training Kit for Developers here: RTM Refresh. The online training kit was also updated.

For more information, see: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/02/02/windows-phone-training-kit-update.aspx

Tuesday, February 1, 2011

The Disposable in SharePoint Development

If you don’t properly dispose of objects in the SharePoint object model that implement IDisposable, you will have memory usage problems in your application. The objects to be most careful of are SPSite and SPWeb, which must be disposed of because they consume large amounts of unmanaged memory.

But Wait… I Thought Garbage Collection Took Care of Memory Management?

The answer to this question is that an object like SPSite uses a mix of managed and unmanaged code. The memory usage of the managed side of SPSite is monitored by the .NET garbage collector, and when enough memory is used by the managed code, the garbage collector will kick in. The problem is that the .NET garbage collector doesn’t watch the unmanaged code’s use of memory and the unmanaged memory use is much greater than the managed memory use. So you can quickly run out of memory on the unmanaged
side without .NET ever feeling like it needs to do a garbage collection.

There are several coding patterns that I use when working with SPWeb and SPSite and other objects that implement IDisposable, so I would like to share with all of you:

Using Dispose with SPSite or SPWeb  object

SPSite oSite = new SPSite("http://localhost");

// Do something

SPWeb oWeb = oSite.OpenWeb();

// Do something

oWeb.Dispose();
oSite.Dispose();

The using clause with SPSite or SPWeb

using (SPSite oSite = new SPSite("http://localhost"))
{
    // Do something
    using (SPWeb oWeb = oSite.OpenWeb())
    {
        // Do something
    }
}

Using Dispose in the finally block of try, catch, finally code

SPSite oSite = null;
SPWeb oWeb = null;
try
{
    if ((oSite = new SPSite("http://localhost")) != null)
    {
        oWeb = oSite.OpenWeb();
        // Do something
    }
}
catch (Exception ex)
{
    // Handle exception
}
finally
{
    if (oWeb != null)
        oWeb.Dispose();

    if (oSite != null)
        oSite.Dispose();
}

Using Dispose with an object in a foreach loop

using (SPSite oSite = new SPSite("http://localhost"))
{
    foreach (SPWeb oWeb in oSite.AllWebs)
    {
        try
        {
            // Do something here
        }
        catch (Exception ex)
        {
            // Handle exception
        }
        finally
        {
            if (oWeb != null)
                oWeb.Dispose();
        }
    }
}

Do Not Dispose of the SPSite and SPWeb Return By SPContext

According to SharePoint best practices, SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext
.Web, and SPContext.Current.Web should not be explicitly disposed by user code.

SharePoint Dispose Checker Tool

Alternatively, you can use SPDisposeCheck to measure your code against known Microsoft dispose best practices.

Friday, January 28, 2011

Command To Start and Stop Windows Services For SharePoint

If you like me who prefer Windows 7 x64 as your SharePoint 2010 development environment, most probably the following batch files would be useful to start and stop Windows Services for SharePoint when required:

Start Windows Services For SharePoint

REM Start SharePoint 2010 Services : http://sharepointmalaya.blogspot.com

Echo Starting Services Required To Run SharePoint 2010

NET START MSSQL$SHAREPOINT
NET START IISADMIN
NET START W3SVC
NET START SPAdminV4
NET START SPTimerV4
NET START SPTraceV4
NET START SPUserCodeV4
NET START SPWriterV4
NET START OSearch14

pause

Stop Windows Services For SharePoint

REM Stop SharePoint 2010 Services : http://sharepointmalaya.blogspot.com

Echo Stoping Services Required To Run SharePoint 2010

NET STOP OSearch14
NET STOP SPWriterV4
NET STOP SPUserCodeV4
NET STOP SPTraceV4
NET STOP SPTimerV4
NET STOP SPAdminV4
NET STOP W3SVC
NET STOP IISADMIN
NET STOP MSSQL$SHAREPOINT

pause

Thursday, January 20, 2011

View SharePoint Content and Settings From Visual Studio 2010

One of coolest and newest features of Visual Studio 2010 is the ability to view SharePoint Content and Settings from Server Explorer.

ServerExplorer

To do this you are require to launch Visual Studio as an administrator. Locate the “Microsoft Visual Studio 2010” shortcut in the Start menu under All Programs > Microsoft Visual Studio 2010. Right click on the Microsoft Visual Studio 2010 shortcut and choose “Run as administrator” from the context menu.

Alternatively, if you just want to make Visual Studio start up with administrator privileges every time you launch it, you can change the
Microsoft Visual Studio 2010 shortcut properties to always run as administrator. To do this, right click on the Microsoft Visual Studio 2010 shortcut and choose Properties. Click the Compatibility tab and then check the “Run this program as an administrator” check box and
press OK.

VisualStudioSettings

Wednesday, January 19, 2011

SharePoint 2010 Disaster Recovery Tools

SharePoint 2010 provides several tools to assist in backing up and restoring your SharePoint content, and you will use a combination of them for complete protection. Test each tool available to you within your environment and see what combination of tools works best with your disaster recovery plan.

The following tools and provides information on how and when to use them:

Versioning

This functionality is disabled by default, but after enabling it, you can restore a previous version of a document from within that library as shown in figure below.

VersionHistory

Versioning does not protect content; it only preserves history by creating copies of content each time it is saved. If a document is deleted, it must be recovered from the Recycle Bin.

Two-stage Recycle Bin

SharePoint 2010 includes a two-stage, first-in/first-out Recycle Bin that allows for a second level of retention before content is permanently deleted from the system. By default, after a user deletes an item and then empties their user-level Recycle Bin, the items are retained in the second stage Recycle Bin for 30 days.

Site collection administrators have access to a global view of the Recycle Bin (see figure below) that includes items deleted by all of the end users and allows the administrator to recover items that have been deleted by other users without affecting the value in the Modified By column.

RecycleBin

Central Administration

SharePoint 2010 Central Administration Backup And Restore interface gives you the ability to perform several types of backups and restores, including:

  • Entire farm
  • Farm configuration only
  • Service applications
  • Web applications
  • Content databases
  • Site collections
  • Sites
  • Lists and libraries
Windows PowerShell

SharePoint 2010 Management Shell provides you with a more flexible and dynamic way to perform backups and restores of your SharePoint information. For more information on STSADM commands, see SharePoint 2010 Backup and Restore using Powershell.

STSADM

The STSADM command-line utility also provides functionality to perform backups of the same components as Windows PowerShell does. For more information on STSADM commands, see SharePoint 2010 Farm Backup and Restore using STSADM.

SQL Server

You can also have SharePoint information backed up by your SQL Server administrators or backup operators from within SQL Server. Similar to performing SharePoint backups, SQL Server backups can be performed using a graphical user interface called SQL Server Management Studio.

Read-only content databases

SharePoint 2010 introduces the capability of recognizing content databases that have been set to read-only in SQL Server. This can be helpful during a disaster recovery to prevent changes from being made to the content during the recovery. The procedure to set the database to read-only can be performed using either SQL Server Management Studio or a T-SQL ALTER DATABASE statement.

Unattached content databases

SharePoint 2010 introduces the capability to access databases that are available in SQL Server but aren’t currently part of the farm. This allows you to perform granular restores of SharePoint content using SharePoint. Accessing unattached content databases will allow SharePoint administrators to connect to read-only content databases, restored SharePoint content databases, and content database snapshots. You are able to restore site collections, sites, libraries, and lists from these unattached content databases.

Tuesday, January 18, 2011

SharePoint STSADM Backup and Restore Commands

The following are examples of different STSADM commands you can use to back up and restore various components of your SharePoint environment.

A full farm backup followed by a restore:

stsadm -o backup -url http://app01/ -directory \\app01\sharepointbackups -BackupMethod Full -Quiet
stsadm -o restore -url http://app01/ -filename \\app01\sharepointbackups –Overwrite

Back up and restore configuration information only:

stsadm -o backup -url http://app01 -directory \\app01\sharepointbackups -configurationonly -quiet
stsadm -o restore -url http://app01 -filename \\app01\sharepointbackups -configurationonly –quiet

Back up and restore a service application:

stsadm -o backup -directory \\app01\sharepointbackups -quiet -backupmethod full -item "Excel Services"
stsadm -o restore -directory \\app01\sharepointbackups -item "Excel Services" –quiet

Back up and restore a site collection:

stsadm -o backup -url http://app01/portalsitecollection -filename \\app01\SharePointBackups\portalsitecollection.bak -overwrite
stsadm -o restore -url http://app01/portalsitecollection -filename \\app01\SharePointBackups\portalsitecollection.bak –overwrite

Export and import a subsite, list, or library:

stsadm -o export –url http://app01/sites/contosoportal/Shared%20documents –filename \\app01\sharepointbackups\SD.bak -quiet -overwrite
stsadm -o import –url http://app01/sites/contosoportal/Shared%20documents –filename \\app01\sharepointbackups\SD.bak -quiet

See also example of performing a SharePoint 2010 Backup and Restore using Powershell.

Monday, January 17, 2011

SharePoint PowerShell Backup and Restore Commands

The following are examples of different SharePoint PowerShell commands you can use to back up and restore various components of your SharePoint environment.

A complete farm backup followed by a restore:

Backup-SPFarm –Directory \\App01\SharePointBackups -BackupMethod Full
Restore-SPFarm –Directory \\App01\SharePointBackups -RestoreMethod New

Back up and restore a service application:

Backup-SPFarm –Directory \\App01\SharePointBackups -BackupMethod Full –Item "Excel Services"
Restore-SPFarm –Directory \\App01\SharePointBackups -RestoreMethod New –Item "Excel Services"

Back up and restore farm configuration information only:

Backup-SPConfigurationDatabase –Directory \\App01\SharePointBackups
Restore-SPFarm –Directory \\App01\SharePointBackups –RestoreMethod Overwrite –ConfigurationOnly

Back up and restore your SharePoint content databases:

Backup-SPFarm –Directory \\App01\SharePointBackups -BackupMethod Full –Item ContosoPortal
Restore-SPFarm –Directory \\App01\SharePointBackups -RestoreMethod New –Item ContosoPortal

Back up and restore a site collection:

Backup-SPSite –Identity http://App01/Sites/ContosoPortal -Path \\App01\SharePointBackups\PortalSiteCollection.bak -Force
Restore-SPSite –Identity http://App01/Sites/ContosoPortal -Path \\App01\SharePointBackups\PortalSiteCollection.bak –Force

Export and import a subsite, list, or library:

Export-SPWeb –Identity http://App01/Sites/ContosoPortal/ -Path \\App01\SharePointBackups\SharedDocuments.bak -Itemurl "Shared Documents" -Force
Import-SPWeb –Identity http://App01/Sites/ContosoPortal/ -Path \\App01\SharePointBackups\SharedDocuments.bak –Force -IncludeUserSecurity

See also example of performing a SharePoint 2010 Farm Backup and Restore using STSADM.

Sunday, January 9, 2011

PowerShell for SharePoint

First things first. Where can we find PowerShell? When running on a SharePoint server, two possibilities exist: either select the SharePoint 2010 Management Shell from the Start menu or open a command prompt and enter the following:

PowerShell

If we’re using the SharePoint management shell, the SharePoint snap-in will already be installed. If we’re using a standard PowerShell console, we can install the snap-in by entering the following command:

Add-PSSnapIn Microsoft.SharePoint.PowerShell

We can check the list of installed snap-ins by using this command:

Get-PSSnapIn

 

Connecting to SharePoint Remotely

We can open a PowerShell session on a client machine and then use remoting to connect to a SharePoint server. To enable remoting on the server, enter the following command:

Enable-PSRemoting
 
This command will enable the WinRM service and set up the firewall to allow incoming sessions. Now, we can connect from any client machine by entering the following command:
 
Enter-PSSession "Server Name" -Credential (Get-Credential)
 

PowerShell Permissions

 
To use SharePoint cmdlets, a user must be a member of the SharePoint_Shell_Access role for the farm configuration database as well as a member of the WSS_ADMIN_WPG group on the SharePoint front-end server. To grant users the appropriate permissions, use the
following command:
 

Add-SPShellAdmin -Username domain\username -database (Get-SPContentDatabase-webapplication http://weburl)

 

Working with Site Collections and Sites

 
Most of the cmdlets commonly used in the management of site collections or sites end in SPSite or SPWeb. To pick up a reference to a site collection, we can use the following:
$site=Get-SPSite -Identity http://siteurl
 
Or we can return a list of all site collections by using this:
 
Get-SPSite

When it comes to managing site objects (SPWeb), we can pick up a specific web site using this:
 
Get-SPWeb -Site http://SiteUrl

or

Get-SPWeb -Site $site

 

Creating Site Collections and Sites

Create a new site collection using the New-SPSite cmdlet:

New-SPSite -Url http://localhost/Sites/NewSiteCollection - OwnerAlias username

Add new sites using the New-SPWeb cmdlet: 


Deleting Site Collections and Sites


We can delete site collections and sites by using the Remove-SPSite or the Remove-SPWeb cmdlet.


or


Setting Properties on SharePoint Objects


$web=SP-GetSPWeb -Identity http://myweburl
$web.Title="My New Title"
$web.Update()

 

Working with Lists and Libraries

Enumerate the lists on a site using the following:

Get-SPWeb -Identity http://myweburl | Select -Expand lists| Select Title

Add new lists using the Add method of the Lists property:

Get-SPWeb -Identity http://myweburl | ForEach {$_.Lists.Add("My Task List", "",$_.ListTemplates["Tasks"])}


Working with Content


Retrieve a list of all items in a site using the following:

Get-SPWeb -Identity http://myweburl | Select -Expand Lists | Select -Expand Items | select Name, Url

Apply a filter to show only documents:

Get-SPWeb -Identity http://myweburl | Select -Expand Lists | Where {$_.BaseType -eq "DocumentLibrary"} | Select -Expand Items | select Name, Url

Use of filters to search for a specific item:

Get-SPWeb -Identity http://myweburl | Select -Expand Lists | Select -Expand Items | Where {$_.Name -like "foo*"} | select Name, Url


Creating New Documents

To create a new document in a document library, use the following:

function New-SPFile($WebUrl, $ListName, $DocumentName,$Content)
{
$stream = new-object System.IO.MemoryStream
$writer = new-object System.IO.StreamWriter($stream)
$writer.Write($content)
$writer.Flush()
$list=(Get-SPWeb $WebUrl).Lists.TryGetList($ListName)
$file=$list.RootFolder.Files.Add($DocumentName, $stream,$true)
$file.Update()
}
New-SPFile -WebUrl "http://myweburl" -ListName "Shared Documents" -DocumentName "PowerShellDocument.txt" -Content "Document Content"

 

Working with Timer Jobs

Get a list of all timer jobs:

Get-SPTimerJob

Or we can get a list of job failures grouped by the job name:

Get-SPTimerJob | Select -Expand HistoryEntries | Where {$_.Status -ne "Succeeded"} | group JobDefinitionTitle

Saturday, January 8, 2011

Renaming The Central Administration Database

Unless you perform a command-line installation, by default SharePoint Central Administration site uses database name with a Globally Unique Identifier (GUID), for example: SharePoint_AdminContent_<GUID>. If you like to rename the Central Administration Database, you can follow these steps but with extreme caution Winking smile:

  • Log on to your SQL Server with an account that has full access; ideally, you should use the same account that you used for your SharePoint installation.
  • Open the SQL Server Management Studio interface and locate the SQL Server instance that contains your Central Administration database, for example: SharePoint_AdminContent_<GUID>. Right-click the database name and choose the Rename command from the shortcut menu to enter edit mode. Then press Ctrl+C to copy the existing name of the database for later use.
  • Back up the existing SharePoint_AdminContent_<GUID> database by right-clicking the name of the database and then selecting the Tasks command.
  • When you have successfully backed up the database, restore the information from the backup that you just performed to a new database having a user-friendly database name such as CentralAdmin_Content_SharePointMalayaDB.
  • Open SharePoint Central Administration. Under Application Management, click Manage Content Databases.
    • Select the SharePoint Central Administration v4 Web application using the Web application drop-down list.
    • Click the old database name, SharePoint_AdminContent_<GUID>.
    • Use the Database status drop-down option to change the status from Ready to Offline.
    • Do not select the option to remove the content database.
    • Click OK.
  • Log on to the SharePoint server using the account that was used to provision the database. Usually this is the service user account that you configured SharePoint with when you provisioned the content databases during the installation of SharePoint 2010.
  • After opening the command prompt, perform the following steps.
    • Type cd C:\Program Files\Common Files\Microsoft Shared\Web server extensions\14\BIN\ to change the directory to the SharePoint 2010 root so you can run the STSADM commands.
    • Delete the original Central Administration database, the one with the GUID that you copied earlier, using the following command:

      stsadm -o deletecontentdb -url http://UrlOfYourCentralAdministration:portnumber –databasename SharePoint_AdminContent_<GUID> -databaseserver NamedInstanceOfYourSqlServer

    • Associate the newly created database with your Central Administration using the following STSADM command:

      stsadm -o addcontentdb -url http:// UrlOfYourCentralAdministration:portnumber -databasename SharePoint_AdminContent_SharePointMalayaDB -databaseserver NamedInstanceOfYourSqlServer

  • Return to SharePoint Central Administration. Under Application Management, click Manage Content Databases and refresh the page to verify that your Central Administration database reflects the new database name.
  • If you see a database with the SharePoint_AdminContent_SharePointMalayaDB name, you can then be sure that the original Central Administration database is backed up, and you can delete it from SQL Server.

CentralAdministrationDBRename

Monday, June 22, 2009

SharePoint Designer 2007 is NOW a FREE Download

A great tool and very happy now it is free, heaps of THANKS Microsoft.

Check out this video :)