Wednesday, October 19, 2011

Infopath 2010 - Switch to read-only view on submit in InfoPath


Use a rule to switch to a read-only view after submit

Add a Rule to the Submit button control on your InfoPath form template that has the following 2 Actions:
           Submit using a data connection: SharePoint Library Submit
and
         Switch to view :  View2

Use code to switch to a read-only view after submit

Add the following C# code to the Clicked event handler of the Submit button control on your InfoPath form template:
       DataConnections["SharePoint Library Submit"].Execute();
          ViewInfos.SwitchView("View 2");

Friday, September 9, 2011

SharePoint 2010 - Error while creating site from Site Template and Resolution

faced a issue while creating a site from a site template. Below is a screen shot of the error.


This error pops up if the site has been restored from a installation where Reporting Services has been installed on Integrated Mode and then restoring the site to a installation where there is no reporting services installed. The content types do not match and hence the error.

Solution:
Install Reporting services in Integrated Mode on the new server and then uninstall the Reporting services feature. This will delete the content types. The re-create the site template and create sites using the template.

Monday, September 5, 2011

SharePoint 2010 - Centered Screen with Fixed Width Design

Steps to be followed:
Step 1: Open up your custom master Page and remove scroll="no" from the body. If you don't do this there will be no scroll bars on long pop up modal windows.


image


Step 2:  Search for “s4-workspace” in the Master Page and remove whole DIV tag and its close Div tag at the bottom of the master page. This ID is tied to a JavaScript file that forces a full width on the page.


Step3: Now Open up your CSS file and add the following:
          body{
                   overflow:auto !important;
                  }
         form 
                {
                  width:980px;
                  margin: auto;
                 }


Step 4: If you wanted to add some background color and borders to enhance the centered design replace it with this:

    body{
            overflow:auto !important;
            background-color: #21374c;
           }
   .s4-widecontentarea{
            background-color: #FFF;
           }
    form
          {
            width:980px;
            margin: auto;
          }




Drawback: 

  1. By default the ribbon is intended to stay static and always be visible to the contributors on the top of the page. However due to the complexity of fixing a site’s width. 
  2. The last draw back to fixing the width of a SharePoint 2010 site is that the content is within a floating <DIV> tag and if the content gets very wide by either a fixed with image or a list with many columns displayed it will spill off the page

Friday, September 2, 2011

SharePoint 2010 - Change the maximum file size to be Uploaded

Login to Central Admin and navigate to


Central Administration -> Application Management -> Manage Web Applications

Highlight the web application that you want to change and then click on "General Settings" tab on the ribbon.



Scroll to the bottom of the list and you will see the maximum upload size the default setting is 50mb this can be can set to a maximum size of 2047mb. If you try to go beyond this it does flag up and tell you that you have exceeded the Maximum size.

Tuesday, August 23, 2011

SharePoint 2010 - Hide the Quick Launch(Quick Way) using Content Editor Web Part


Just add a the Web Part Content Editor and add the following text in the HTML Source mode:

/*--Hide Quick Launch --*/



<style type="text/css">
#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}

</style>

Monday, August 22, 2011

SharePoint 2010 Publishing - Programmatically inheriting master page from parent site


Below is a code snippet for Programmatically inheriting master page from parent site

PublishingWeb area = PublishingWeb.GetPublishingWeb(web);
                area.Navigation.InheritGlobal = true;

                area.MasterUrl.SetInherit(truetrue);
                area.AlternateCssUrl.SetInherit(truetrue);


                area.Update();

Note: Add reference to Microsoft.SharePoint.Publishing.dll

Wednesday, August 10, 2011

SharePoint 2010 - Use [Today] and [Me] in Calculated Column


If you try to create column with field type : calculated and want to use current date as part of formula , the first thing that comes up in mind is to use [Today] as SharePoint gives it as filter option while creating views. But unfortunately if you try to add ‘[Today]‘ in formula, it gives error : “Calculated columns cannot contain volatile functions like Today and Me”


Same error goes when trying to use “[Me]” too.
Well, a nice trick can allow you to do this.

  • Open up the List Settings page where you want this column.
  • Create column named “Today”. The type doesn’t matter here, so let type as “Single Line of Text” and just click “Ok”.
  • Now create the calculated column where you need to use current date within formula and add “Today” from available columns
  • Once this is done, we no longer need that our own generated column “Today” so you can delete it (Although when you need to edit formula you will need this again, so either recreate this dummy Today field or make it hidden using code behind. Otherwise SharePoint will put you again on that error screen).
    This will trick the SharePoint to use [Today] (current date) as part of formula. 


    You can apply same trick for the current user i.e. [Me] too. Create a dummy field named “Me” use it in your formula, save the calculated column, and delete that dummy “Me” field.



    For calculated fields, calculated value is stored in Database when item is created at first time and doesn’t change until item is edited. So using Today doesn’t means each time you will get value re-calculated as per actual today’s date. For that it is better to use Computed column.


    This trick tells how you can use Today & Me for calculated fields. Its secondary thing whether to use them or not. This totally depends upon usage of calculated field. For example you can use this in project management site for issues list, whenever new issue item is created you need to auto calculate the minimal duration and base on production push date of solution.




Saturday, July 9, 2011

SQL - Steps for connecting SQL server 2008 from sqlserver 2005 management studio

issue while I want to connect SQL server 2008 from SQL server 2005 management studio due to forward compatibility. I got solution for that by using below mentioned Steps
  1. Click the Windows "Start" button and select "All Programs." Click the "SQL Server 2005" program group and then click "SQL Server Management Studio" from the list of shortcuts. This opens your database console screen.

  2. Click your 2005 database name on the left side of the window. Click the "New Query" button to open your query window.

  3.  Type the following code into your query window:


    EXEC sp_addlinkedserver '2008Server','SQL Server';
    Replace "2008Server" with your SQL Server 2008 server name. The "N'SQL Server'" text tells the stored procedure to use the SQL Server drivers to connect

  4. Press the "F5" key to execute the statement and connect to the server. The new linked server name is displayed on the left of your window.

Wednesday, June 8, 2011

JS - Javascript to close window

java-script to close window on page_load event.

if (!Page.ClientScript.IsClientScriptBlockRegistered("Logout"))                               Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Logout", "<script>window.open('','_self',''); window.close();</script>");




This will work in IE, Chrome butthis will not work in FireFox

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);

Saturday, February 12, 2011

Sharepoint - Empty Recycle Bin


Introduction:
With SharePoint User level recycle bin(that is displayed in Quick Launch), there is no way to ‘Empty’ the recycle bin in a single go. We have this option in Site Collection Recycle Bin. May be this is done deliberately to prevent users from deleting all items by accident! This is definitely a fallback from developers perspective.
Description:
A way to Empty  the recycle bin without going through the pain of manually deleting each of the files or selecting the files and clicking on the ‘Delete Items’ button.
·         Open your SharePoint Recycle Bin Page by clicking on the Recycle Bin icon on the Quick Launch.
·         Simply copy the below JavaScript statement into the address bar and click Enter.
javascript:emptyItems();
Note
Be careful as all of the items will not be to sent to Site Collection Recycle Bin. This a good tip for development phase.

Thursday, February 3, 2011

SharePoint 2010 - Object Model Code on External List - BDC Exception Solution


When you're working with the Object Model Code on an external list in SharePoint 2010 you might stumble upon the following problem:
Microsoft.BusinessData.Infrastructure.BdcException: The shim execution failed unexpectedly - Proxy creation failed. Default context not found..
---> Microsoft.Office.SecureStoreService.Server.SecureStoreServiceException: Proxy creation failed. Default context not found.
This is caused by the fact that there is no default SPServiceContext, meaning SPServiceContext.Current is always null. The problem is that, for example, when you are working with methods like listitems.getdatatable() you need a current context, since the underlying code will use SPServiceContext.Current
To solve this issue you can create a code block that will fill the current SPServiceContext:












using (var site = new SPSite("http://localhost"))
{
// Get context for the site.
var context = SPServiceContext.GetContext(site);
// Assign context in SPServiceContext.Current
using (var scope = new SPServiceContextScope(context))
{
...
listitems.getdatatable()
}
}
After closing the using codeblock your current SPServiceContext will be empty again.