Friday, April 22, 2011

SharePoint 2010 - Copy DLL from GAC [Assembly]


Please find the following approach to copy a DLL from GAC
Using SUBST Command
Go to Windows DOS Prompt and type  following command and press enter. 
SUBST L:  “C:\Windows\Assembly”

This command will create a virtual drive “L” and this drive will have the internal view of GAC, where C:\Windows\Assembly will have the abstract view of GAC. Kindly ensure that the drive name that you type in SUBST command, it must not exist in your system. Go to My Computer and you will see the Drive named “L:”.

Now to delete this drive, run this command on command prompt.

SUBST L: /D

This will delete the L: drive

Friday, April 15, 2011

SharePoint 2010 - Move all databases


Move all databases (SharePoint Server 2010)

This article describes how to move all of the databases associated with Microsoft SharePoint Server 2010 from one database server to another database server. If your databases are hosted on different servers, this procedure applies to the database server that hosts the configuration database. For moving content databases only, see Move content databases (SharePoint Server 2010). For moving service application databases only, see Rename or move service application databases (SharePoint Server 2010).
Moving databases makes all farm sites and assets unavailable to users until the process is completed.

The following kinds of databases hosted on a single database server can be moved by using the procedures in this article:
  • Configuration database
  • Central Administration content database
  • Content databases
  • Service application databases

Moving all databases

The process of moving all of the databases from one database server to another database server requires you to work in both SharePoint Server 2010 and SQL Server. The following list summarizes the process of moving all databases, with detailed steps presented in the subsequent procedures:
  1. Prepare the new database server.
  2. Close any open Windows PowerShell management shell windows and any open Stsadm command prompt windows.
  3. In the Services Microsoft Management Console snap-in, stop all of the services related to SharePoint Server 2010 and Internet Information Services (IIS). For details.
  4. In SQL Server, detach the databases from the current instance. For details, see To detach databases.
  5. Using Windows Explorer, copy or move the .mdf, .ldf, and .ndf files associated with the database from the source server to the destination server. For details.
  6. In SQL Server, ensure that all of the SQL Server logins, fixed server roles, fixed database roles, and permissions for the databases from the source server have also been configured correctly on the destination server.
  7. In SQL Server, attach the database to the new instance.
  8. Use SQL Server connection aliases to point to the new database server, and then use the connection alias to update all Web servers. A connection alias is a defined alternate name that can be used to connect to an instance of SQL Server. You have to configure the alias on all Web servers and application servers in the farm.
  9. Restart the services.
  10. The following are the minimum permissions that are required to perform this process:
  • You must be a member of the Farm Administrators SharePoint group.
  • On the computer that is running the SharePoint Central Administration Web site, you must be a member of the Administrators group.
  • On the database server from which the databases are being moved, you must be a member of the following:
    • The Administrators group
    • The db_backupoperator fixed database role
  • On the database server to which the databases are being moved, you must be a member of the following:
    • The Administrators group
    • The db_owner fixed database role
In some environments, you must coordinate the move procedures with the database administrator. Be sure to follow any applicable policies and guidelines for managing databases.


Detailed Steps:


To prepare the new database server

  • Configure the new database server. (With Same Version of previous one.)

To close any open management sessions

  • Close any open Windows PowerShell management shell windows and any open command prompt windows if you have been running the Stsadm command-line tool.

To stop the farm

  1. On the server that is running the Central Administration Web site, in the Services snap-in, stop the following services:
    • SharePoint 2010 Administration
    • SharePoint 2010 Timer
    • SharePoint 2010 Tracing
    • SharePoint 2010 User Code Host
    • SharePoint 2010 VSS Writer
    • SharePoint Foundation Search V4
    • World Wide Web Publishing Service
    • SharePoint Server Search 14
    • Web Analytics Data Processing Service
    • Web Analytics Web Service
  2. On the server that is running the Central Administration Web site, at the command prompt, type iisreset /stop.

To detach databases

  • In SQL Server Management Studio on the original database server, detach the databases that you want to move from the instance that they are attached to. If you are running many databases, you may want to run a Transact-SQL script to detach databases.

To move database files to the new server

  • Using Windows Explorer, locate the .mdf, .ldf, and .ndf files associated with each database that you are moving, and then copy or move them to the destination directory on the new computer that is running SQL Server.

To set up permissions on the new server

  • On the destination database server, open SQL Server Management Studio and transfer your logins and permissions from the original instance to the destination instance. We recommend that you transfer permissions by running a script.

To attach databases to the new instance of SQL Server

  • On the destination database server, attach the databases to the new instance.


To point the Web application to the new database server by setting up SQL Server connection aliases

  1. Start SQL Server Configuration Manager. On the Start menu, point to All Programs, point to Microsoft SQL Server 2008, point to Configuration Tools, and then click SQL Server Configuration Manager.
  2. Expand SQL Native Client Configuration, right-click Aliases, and then click New Alias.
  3. In the Alias Name field, enter the name of the original SQL Server instance, for Protocol, verify that TCP/IP is selected, for Server, enter the name of the new server that is hosting the SharePoint Server 2010 databases, and then click OK.
  4. Repeat this procedure on each Web and application server.
  5. Optional. If your environment relies on System Center Data Protection Manager (DPM) 2010 or a third-party application that uses the Volume Shadow Copy Service (VSS) framework for backup and recovery, you must install the SQL Server connectivity components on each Web server or application server by running SQL Server setup.

To reconfigure Web Analytics database locations

  1. On the SharePoint Central Administration Web site, under Application Management, click Manage Service Applications.
  2. Select the Web Analytics service application, and then click Properties.
The Edit Web Analytics Service Application wizard appears.
  1. Click Next.
  2. On the second page of the wizard, update the location of each Web Analytics database to the new SQL Server instance, and then click Next.
  3. In Central Administration, under System Settings, click Manage Services on Server.
  4. Stop and restart the Web Analytics Data Processing Service, and the Web Analytics Web Service.
  5. After moving databases, you should manually run the health rule "Web Analytics: Verifies that the SQL Server Service Broker is enabled for the Web Analytics staging databases." To manually run the health rule, follow these steps:
    • In Central Administration, click Monitoring.
    • In the Health Analyzer section, click Review rule definitions.

      The All Rules page is displayed.
    • Under Category: Configuration, click the health rule Web Analytics: Verifies that the SQL Server Service Broker is enabled for the Web Analytics staging databases.

      The
      Health Analyzer Rule Definition dialog box opens.
    • On the ribbon of the Health Analyzer Rule Definitions dialog box, click Run Now.

    To restart the services in the farm

    1. On the server that is running the Central Administration Web site, at the command prompt, type iisreset /start.
    2. In the Microsoft Management Console Services snap-in, start all of the services related to SharePoint and Internet Information Services (IIS). These include the following services:
      • SharePoint 2010 Administration
      • SharePoint 2010 Timer
      • SharePoint 2010 Tracing
      • SharePoint 2010 User Code Host
      • SharePoint 2010 VSS Writer
      • SharePoint Foundation Search V4
      • World Wide Web Publishing Service
      • SharePoint Server Search 14
      • Web Analytics Data Processing Service
      • Web Analytics Web Service

Friday, April 8, 2011

SharePoint 2010 and Outlook 2010 Integration

Outlook 2003 and SP 2010 – cannot connect to document libraries, cannot overlay calendars, one way synchronization in calendar and contacts (sharepoint -> outlook)
Outlook 2007 and SP 2010 – nearly identical to using Outlook 2010


Linking SPF 2010 document libraries to Outlook 2010
Pros:
  • Take files offline to work with them in Outlook
  • Use Outlook’s built in viewer to see in documents (for supported formats)
How to link to a document library:
  1. Open Document Library you want to connect to in SharePoint 2010
  2. Click on the ribbons “Library” tab
  3. Connect & Export section > Click Connect to Outlook icon (labels may be hidden by screen size/resolution)
  4. Popup window > Click Allow (to allow Outlook to be used)
  5. Popup window > Click Allow (to allow transfer of content-may not appear)
  6. Outlook 2010 will open and popup asks if we want to connect > Click Advanced
  7. Change name and description of document library if desired > Click OK
  8. Click Yes
  9. Verify access by logging into SharePoint from Outlook
  10. View documents in library in Outlook
How to delete a connection to a document library
  1. In Outlook 2010, scroll down left column to SP lists
  2. Select name of linked library you want to remove
  3. Right click > Delete Folder >ok (go ahead, click it! Don’t be scared!)
  4. Library is removed from Outlook Account
Linking SPF 2010 Calendars to Outlook 2010Pros:
  • Snynchronization is two-way – so you can add a new item to a SP calendar in Outlook. Make sure you have only the SP calendar visible so it is on the correct calendar. Note: Synchronization occurs at a specified interval – you may need to refresh the calendar page to see it.
  • Overlaying multiple SP calendars is a good way to keep track of SP groups when you are involved in many different projects or areas of operations.
Link to SP calendar
  1. Go to a Calendar List in SP 2010 > Calendar Tab
  2. Select “Connect to Outlook”
  3. Ok
  4. Advanced > name & description > ok
  5. Yes
  6. Connect to site with password if needed
  7. You have a link to SP calendar in the new Other Calendars section – Outlook will display the new calendar by default, so you will see two side-by-side calendars.
Overlay calendars in Outlook
  1. At the top of the SP calendar in Outlook, Click on the left-facing arrow
  2. You will now see the overlay view
  3. Click on the right arrow on the SP calendar tab to undo
  4. Click on the checkboxes in the left column to hide and show specified calendars & calendar groups
Note: on the right of the ribbon is “Calendars Overlay” – you can overlay SP Calendars. In Outlook you can overlay SP and Outlook Calendars.
Linking SPF 2010 Contacts to Outlook 2010

Create a new contacts list
  1. Site Actions > More Options > Contacts
  2. Call it MySPContacts and select Create
  3. Add some new names with AddNewItem
Connect new contact list to Outlook
  1. List Tab > Connect to Outlook
  2. Go through the verification logins and name/description process
  3. Outlook menu > view > change view > list
Contacts Features in sp 2010
Note: views are individual to contact list – contacts cannot be an overlay like outlook and sp calendars
Share Outlook Task list pulled in from SP

Tasks list > Highlight list > Folder tab > share tasks > send email to task list


Overlay SP Calendars
  1. Calendar page > calendar tab > Click on Calendars Overlay
  2. Click on New Calendar
  3. Type in name & click on resolve
  4. Select color for overlay
  5. Select calendar on SP calendar you want to overlay
  6. Select calendar list view you want to overlay
  7. Click OK
Overlay Personal Outlook Calendars in SP

1. Calendar page > calendar tab > Click on Calendars Overlay
2. Click on New Calendar
3. Type in name and click on Exchange radio button
4. Click on Find
Note: This should work automatically – users must have corresponding Exchange email in SP Profile – ensure that profiles are in sync with Active Directory and exchange for email – This will get the current users email from the profile information and use that to pull in correct Exchange calendar(s) – doesn’t work with outlook 2010 – needs service pack 1 – or may need ssl applied appropriately
5. Outlook Web Access URL & Exchange Web Service URL should appear
https://mail.site.com/owa/
https://mail.site.com/ews/exchange.asmx
6. Click OK

Create an alert or subscribe to RSS feed – up to date changes  on documents, lists, list items, etc.

Create an alert
1. Click on list, item, etc. you want to get alerts for
2. Click on Tools tab > Items > Alert me > manage my alerts
3. Click on radio button next to selected list
4. Fill in alert specifications
Note: In particular, you may want to consider whether to send an alert immediately, daily, or weekly
5. Click ok
6. You can add as many alerts as you want
Note: You can also go to Tools > List > set an alert on this list. You will get a popup dialog rather than be sent to a different page.
Subscribe to rss feed
  1. Navigate to the list or library or view  you want to set up feed for
  2. Click on feed button in ribbon
  3. Click on subscribe to feed link
  4. Synchronize Outlook and Common Feeds list in Windows
    1.  
      1. Outlook > File > Options > Advanced
      2. RSS Feeds section > Check off “Synchronize RSS feeds to the Common Feeds List (CFL) in Windows”
      3. Click ok
  5. Close and reopen Outlook; feed should now appear in RSS Feeds in left column
Note: for a view feed, click on View > Modify this view > Feed button
Outlook Web parts
They don’t appear to work properly with 2010, supposedly works fine with 2007 

jQuery - Using jQuery to attach regular expression validation(no special character to be added in Title field) to a SharePoint list form field

Write the below code on the New Form of the SharePoint list.

<script type='type/javascript'>
  
  _spBodyOnLoadFunctionNames.push("attachToTitleField");
  
  function attachToTitleField() {
   var titleField = $('input[title=Title]'); //Find title field on the form
   
   //Add a DIV element to provide a place for an error message from the RegEx validation
   titleField.parent().append("<div id='GilesH_titleValidation'></div>");
  
  //Use jQuery to attach the validateAlphanumeric function on keyup
  titleField.keyup(function() {
   validateAlphanumeric(titleField.val());
  });
 }

 function validateAlphanumeric(stringValue) {
  
  //Allows alphanumeric only for the 1st character
  //after the 2nd character, alphanumeric and spaces allowed upto 255 characters
  var regExpressionValue = /^[0-9A-Za-z][0-9A-Za-z\s]{0,255}$/; 
  var re = new RegExp(regExpressionValue);
   
  if (stringValue.match(re)) {
   //alert("Successful match"); //Debug
   
   //Allow Save
   $('a[id=Ribbon.ListForm.Edit.Commit.Publish-Large]').attr("style", "display:inline-block;"); //Show Ribbon Save Button
   $('input[id*=SaveItem]').attr("disabled",""); //Re-enable Form Save Button
   
   //Blank Error Message
   $('div[id*=GilesH_titleValidation]').text(""); //Blank custom error message
  } else {
   //alert("No match"); //Debug
   
   //Stop Save
   $('a[id*=Ribbon.ListForm.Edit.Commit.Publish-Large]').attr("style", "display:none;"); //Hide Ribbon Save Button
   $('input[id*=SaveItem]').attr("disabled","true"); //Disable Form Save Button
   
   //Provide Error Message
   $('div[id*=GilesH_titleValidation]').text("The title you have entered is invalid. Only alphanumeric characters and spaces are allowed.");
  }
 }

 </script>


N.B: Add an extra <DIV> element next to the Title field to notify the user of what is going on.

Monday, April 4, 2011

LINQ - Dynamic sort with LINQ

Dynamic sorting using LINQ. City class is defined below.

public class City
{
   public string Name { get; set; }
   public string Country { get; set; }
}
The collection is initialised using this code
List<City> cities =
           new List<City>
           {
               new City{ Name = "Sydney", Country = "Australia" },
               new City{ Name = "New York", Country = "USA" },
               new City{ Name = "Paris", Country = "France" },
               new City{ Name = "Milan", Country = "Spain" },
               new City{ Name = "Melbourne", Country = "Australia" },
               new City{ Name = "Auckland", Country = "New Zealand" },
               new City{ Name = "Tokyo", Country = "Japan" },
               new City{ Name = "New Delhi", Country = "India" },
               new City{ Name = "Hobart", Country = "Australia" }
           };

A typical example of applying a sort will be to write such a query.
var collection =
   from c in cities
   orderby c.Country
   select c;



Here we are sorting the collection on country. Note this is static in nature.Code above can only sort by country. If we want to sort by city name then  we have to write another query and maybe use a conditional construct such as if or switch and write a method which takes in a parameter. While this will work, it is not the best way to do it. LINQ gives us the ability to make our code dynamic. we can provide sort functionality for the query by writing a method which takes in a Func<TElement, TKey> delegate. This delegate is used by the OrderBy extension method. 

public static void Sort<TKey>(List<City> cities, Func<City, TKey> selector)
{
   var sortedCollection =
       from c in cities
       orderby selector(c)
       select c;
   foreach (var item in sortedCollection)
   {
       Console.WriteLine(item.Name);
   }
}


This method can be called by passing in the cities collection which has been initialised earlier.
Sort(cities, c => c.Name);
we  can also sort by country without changing my query. To sort by country we just need to call my sort method like this.
Sort(cities, c => c.Country);