Wednesday, August 29, 2012

Data Migration - "Created By" Field Nightmare

As Sharepoint consultants we have often been faced with this opportunity to port the data across environments. I came across such a scenario in one of my recent engagements where I had to push all the data from Excel to Sharepoint Lists.

Below I used data migration from excel sheet, but if any migration tool that you have used does not support for the migration of created by and created date fields - you can fine tune the below code to your benefit.
 

Couple of issues I would like to address which I faced and the solutions to those to help my SharePoint community members.

1. Import n excel sheet to create a List via the Sharepoint User Interface - This has worked fine except that the look ups were not carried through in the List. I had to update the column types after the create.


 
 
 
 

 
 
 
 



 
The look up column for Country needed to be changed
 
 
 
Note : If the Excel column for Country did not have values from the data validation list, then you will need to add those values in the choice column above. By default it takes all the values form the Sharepoint column and converts it to a choice. 
 
 
2.  "Created by" fields were mirrored with admin account. I needed to now convert these to the users who had created them since there was functionality to display only your own items to contributors.
 




Here is a Visual web part I came up with to update the "Created by" and "Modified by" field to any other user based on an additional column value - "CopyCreatedBy" to update the user name. 
 
 
 
For entering data - I could not view the List in data sheet view, Some research on the net showed I needed to install this below.
If you do not see the data sheet view - Install the update for X64, to access Data sheet view. 2007 Office System Driver: Data Connectivity Components
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23734
OK, That sorted that issue out. Now I entered some data for the user names.
 
 
 
 
UX:
 
 
 
 
 The below code is not permormance savvy since it uses the crude way to access the list & data.
Although the code works fine and performs great in a local environment, issue is with the way the Items property is accessed. The Items property queries ALL items from the Content Database for the current SPList and “unfortunately” does that every time we access the Items property. The retrieved items ARE NEVER CACHED. In the loop the Items property is accessed twice for every loop iteration – once to retrieve the Count, and once to access the actual Item identified by its index.
 
Code:
 using System;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Web.UI.WebControls.WebParts;  
 using Microsoft.SharePoint;  
 namespace ChangeUserName.ChangeCreatedBy  
 {  
   public partial class ChangeCreatedByUserControl : UserControl  
   {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
       if (!IsPostBack)  
       {  
         lblerror.Visible = false;  
         txtListName.Text = "";  
         txtwebSite.Text = "";  
         txtCopyCreateByCol.Text = "";  
       }  
     }  
     protected bool validate()  
     {  
       if (txtListName.Text =="" ||txtwebSite.Text == "" || txtCopyCreateByCol.Text == "")  
       {  
         lblerror.Visible = true;  
         lblerror.Text += "Please enter the Required Fields with *" ;  
         return false;  
       }  
       return true ;  
     }  
     protected void Update_Click(object sender, EventArgs e)  
     {  
       if (validate())  
       {  
         lblerror.Text = "";  
         try  
         {  
           using (SPSite site = new SPSite(txtwebSite.Text))  
           {  
             using (SPWeb web = site.OpenWeb())  
             {  
               SPList list = web.Lists[txtListName.Text];  
               foreach (SPListItem item in list.Items)  
               {  
                 web.AllowUnsafeUpdates = true;  
                 SPUser user = web.EnsureUser(item[txtCopyCreateByCol.Text].ToString());  
                 string value1 = user.ID + ";#" + user.Name;  
                 item["Author"] = value1;  
                 item["Editor"] = value1;  
                 item.Update();  
               }  
               list.Update();  
               web.Update();  
               lblerror.Visible = true;  
               lblerror.Text = "Successfully updated the created by field for all records of the list : " + txtListName.Text;  
             }  
           }  
         }  
         catch (Exception ex)  
         {  
           lblerror.Visible = true;  
           lblerror.Text += "All Records could not be updated. " + ex.Message.ToString();  
         }  
       }  
     }  
   }  
 }  

Tuesday, August 7, 2012

Sharepoint Tools to our rescue...

Frequently used SharePoint development, administration tools at a glance...
(Did I mention Free!)

1.       
CAML (Collaborative Application Markup Language) is an XML-based query language that helps you querying, building and customizing Web sites based on Windows SharePoint Services. The XML elements define various aspects of a WSS site.

The tool will help you build, test and execute your CAML Queries. 
2.       
Automated SharePoint 2010 PowerShell-based installation script
3.       
Add a function to list the action button, the ability to export history version of the item sheet to Excel from the specified date
4.       
This project will host a collection of several PowerShell scripts/ modules. At present, this project has only one module for downloading SP2010 prerequisites, creating a new SP install package.
5.       
SPLabs is a set of labs, either VB.NET or C#, focused on SharePoint technologies. Each lab is in itself a tutorial to learn a specific area of SharePoint
6.       
The SharePoint Manager 2010 is a SharePoint object model explorer. It enables you to browse every site on the local farm and view every property. It also enables you to change the properties
7.       
The Property Bag Settings can store any metadata as Key-Value pairs such as connection strings, server names, file paths, and other miscellaneous settings needed by your SharePoint application.
8.       
This program will synchronize files and directories from and unc/local/SharePoint to a SharePoint 2007 or 2010 server. Supports of to 2GB files and both manually and timer based syncs. Setting metadata on files is also supported.
9.       
The SharePoint Service manager lets you start and stop all the SharePoint 2010 services on your workstation.
10.   
SharePoint 2007 used to have a type of Site Called Site Directory which provided a directory of all sites that had been created. In SharePoint 2010, this feature has been dropped. This solution has been developed to fill the gap in SharePoint 2010. The solution follows the same basic principle of the Site Directory in SharePoint 2007 but adds some commonly requested features.
11.   
This is a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.
12.   
Super easy installation of WSP files on different servers in your OTAP environments
13.   
Tool to query FAST for SharePoint and SharePoint 2010 Enterprise Search. It utilizes the search web services to run your queries so you can test your queries remotely from your local machine. It shows your results, allows you to refine your query (FAST), and page your results.
14.   

ULSViewer allows users with access to ULS log files to view their logs in a more user friendly interface instead of using standard log file viewers. Logs opened can be filtered, sorted, highlighted, appended, etc. in order to single out the data that is important to the user. This information can be used to diagnose problems with machines running ULS services, or to monitor machines and the events they create.

The ULSViewer tool runs on either 32 or 64 bit architectures of Microsoft Windows 2003 Server, Windows 2008 Server, Windows 2008 Server R2, Windows 7, Windows Vista, and Windows XP.

Warning: The ULSViewer tool is an unsupported application that can be used to analyze ULS log files. Microsoft does not provide support for this tool. Use this tool at your own risk. Microsoft Product Support Services (PSS) cannot answer questions about the ULSViewer tool.
15.   
This feature adds the hyperlink List Properties to the List Settings page in the General Settings section.
16.   

This PowerPack extends PowerGUI with a set of folders, nodes and actions that allow you to manage SharePoint 2010. SharePoint 2010 is the first version of SharePoint that includes PowerShell cmdlets to manage, configure and monitor your SharePoint Farm. This Powerpack pulls some missing/buried functions from Central Admin into PowerGUI
17.   
This tool can create a very high level report of your farm configuration. Download is available in 32-bit & 64 bit version.
18.   
Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.
Fiddler is freeware and can debug traffic from virtually any application that supports a proxy, including Internet Explorer, Google Chrome, Apple Safari, Mozilla Firefox, Opera, and thousands more. You can also debug traffic from popular devices like Windows Phone, iPod/iPad, and others.
To debug applications you've written in Java, .NET, or using WinHTTP, see this page.
19.   
SharePoint Designer 2010 is the tool of choice for the rapid development of SharePoint applications. Using SharePoint Designer, advanced users and developers alike can rapidly create SharePoint solutions in response to business needs. Advanced users can compose no-code solutions that encompass a variety of common scenarios, from collaborative sites and web publishing to Line-Of-Business data integration, business intelligence solutions, and human workflows, leveraging the building blocks available in SharePoint in an easy to use environment. In addition, developers can use SharePoint Designer 2010 to get a quick start on SharePoint development projects.​
20.   
This tool can be used for content deployment purpose in SharePoint 2010 environment. Content can be published at site collections level, webs, lists, folders, and list items (including files).
21.   
This is a clean, commented starting point for creating your own SharePoint 2010 branding. Starter Master Pages were known previously as Minimal Master Pages in SharePoint 2007. Good to go as initial start
22.   
In MOSS 2007 and SharePoint Server 2010 we can’t look our alerts with List Name, we can look them with username. some cases we can recover the time loss ,to see alerts with the list name, at the same time we can see alerts with username like SharePoint Server 2010 or MOSS 2007 with this tool
23.   
CAML.NET intellisense is a Visual Studio 2010 plugin for writing SharePoint xml element files. This plugin provides intellisense in SharePoint xml schema files with description.
24.   
SPDisposeCheck is a Visual Studio 2010 plugin or separate tool -0This tool helps to find objects in your code that is not properly disposed. But when using this tool in big projects there are some caveats – sometimes it reports incorrectly and without specifying code line, so the best choice is to use MSDN page about disposing objects and check of you have any doubts.
     25.
SP Migration Tools
With the release of the new version, SharePoint is getting day by day more popular amongst organizations. It is just a matter of time until a decision is made to migrate from an older version of SharePoint or even from a different enterprise content management (EMC). The following third-party solutions will help SharePoint Administrators to migrate or consolidate content, Some of them are paid and evaluations are welcome!
     26.
Power shell builder
A new tool that is my getting on my favorite list fast, power shell command builder. A great User Interface to build power shell commands in all Sharepoint versions