this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Monday, December 26, 2011

OOB: Change master page from SharePoint 2010

Most of time we don’t prefer to use conventional user interface provided by SharePoint when we configure it. We want our separate identity when we try to publish our site on base of SharePoint framework.

When you try to find out Changing of master page in your SharePoint, you may not get that options in your Site Settings, first you need to do is to Enable “SharePoint Server Publishing Features”.

To enable above features follow below steps..

Go to Site SettingsàSite Collection Administration à Site Collection Features à Activate SharePoint Server Publishing Features.

Now you may able to see Master pages menu in the Site setting under Look and Feel depends on the version you have installed on your machine.

Alternatively you can directly go to change master page with _layouts/ChangeSiteMasterPage.aspx , just add below url with your site and you will be redirected to change master page for your site.

How to get public key token for my dll or exe?

Sometime we need to find our dll or exe’s public token when we have strongly signed out. There is a very nice tool given by .net is sn.exe

Just go to command prompt of visual studio, and type following command. Here please note that you need to set your application folder path where your dll or exe assembly is stored.

Sn – T abc.dll

This will give us public token of abc.dll like below message

Public key token is c8903c1b3f99ec16

Wednesday, December 14, 2011

Install SharePoint 2010 on windows 7 64 bit

Most of time in case of development It would require to install sharepoint on the non-server os, As we know sharepoint 2010 can only be installed on the 64bit operating system. Now we have one choice to create environment on the Windows 7 64bit os.

If we don’t dig more on it, we have choice to install as standalone sharepoint but instead of that we would like to have sharepoint farm configuration and we don’t wish to install SQL express by Sharepoint installation but we have our own SQL server then?

Also to enable installation on Windows 7, we require changing in configuration file and that is to add one setting for it.

Below things require to add at ..\files\Setup\Config.xml

If you don’t add above setting, setup will give you error and you won’t be go further.

Next thing for using your own SQL server installation is to create Sharepoint Configuration database and that can be done with help of Powershell command named SP-NewConfiguationDatabase

Once you use above command in the powershell you will be asked to enter required details for your server and database creation.

To use above command please note that, you are going to use your windows user in it, so you need to give full qualified name.

Like mypc\user, if you don’t give full name it will give you error.

Reference:

http://msdn.microsoft.com/en-us/library/ee554869.aspx -for Installing Sharepoint

http://technet.microsoft.com/en-us/library/ff607838.aspx -for configuration database creation.

http://spdeveloper.net/2010/06/errors-when-installing-sharepoint-2010-in-windows-7-development-environment/ --for possible error we could have in creating configuration database.

Wednesday, November 30, 2011

How to Resolve Activate disabled Sandbox solution in SharePoint 2010

This problem mainly occurs when you start to develop sandbox solution and upload you solution to fresh SharePoint farm, if you have already developed some sandbox solution and some admin is maintaining SharePoint farm, you may never come to such problem.

Situation was, I was able to add solution to my site and I was also able to see SharePoint WSP and all was looking great, but when I was going to activate it, it didn’t seem to work and it was showing me user right tooltip, which usually comes up when we have not enough permission to access anything.





I wonder about my permission and I doubled check my permission but there was not an issue, then after checking about other problem if there could be.. but nothing was there.

After google, I found that there was issue of service named “Microsoft SharePoint Foundation Sandboxed Code Service” required to start prior to activating any sandboxed solution. This service can be activated from Central admin ->System Settings ->Server -> Manage Service on Server-> Start Service Microsoft SharePoint Foundation Sandboxed Code Service start

Reference: I found that useful information here

Connected WebParts in SharePoint 2010

SharePoint has very cool features of connected Web Parts, It simply means that two different web parts are connected and they can share data between them.

In Connected Web Parts there are basically two things required at least, one is Consumer Web Parts and Provider Web Parts. Consumer Web Parts gets data from Provider Web Parts, and this data passing is usually done with use of interface.

Connected web parts are best when we have two different web parts and we want to change web parts activity based on external events happen in another web part exist in the same web page.

Here, MSDN contains very nice walk through for creating connected web parts.

In above article, two attributes plays role for connecting web parts

ConnectionProvider:

It should be attached to any one method which returns data, it does not necessary that it must have some value specified in the bracket, what so ever you write there will be displayed when you access web parts from SharePoint site.

ConnectionConsumer

It should be attached to any one method which gets data from another web part.

NOTE: when you use this connected web parts in Web Part page added in sharepoint, you will have option to connect with consumer web parts. But in case of default page you may require to turn to edit mode of your page and then click on edit of web part and then you will have this options of connecting to another consumer web part.

In above scenario it is assumed that firstly we have added both consumer and provider web parts in the page and then we will have option to connect web parts.

Tuesday, November 29, 2011

Thoughts on Web Parts in SharePoint 2010

SharePoint 2010 has many inbuilt functionality and features. One can leverage on it and take advantage of out of box SharePoint development. But business is all about having information in the right way and at a certain moment easy to catch.

Most of case Web parts serve many business needs for showing up information in the customized forms when SharePoint out of box development does not provide enough information.

At the time of Web Parts creation in SharePoint 2010, one has two choices Visual Web Parts and Standard Web Parts.

Both of these are much useful on their way and most of asp.net developers are much familiar with Standard Web Parts because it is very much similar to that of asp.net developers. Visual Web parts allows developer to just drag and drop control as they do in most of asp.net pages, you will have availability of all standard web controls, you don’t need to take care of setting underlying properties of controls. On the other hand Standard web parts allows developer to set each and every property at run time, you can have more controls on each controls. You can create as many controls as you need; you can dispose your control when you don’t need it.

There can be debate of using Standard Web Parts and Visual Web Parts, but certainly it depends on the choice of developer and business nature. Sometimes it is noted that Standard Web parts gives good performance compared to Visual Web Parts, and at the same time you need to take care of many things when you develop Standard Web Parts compared to Visual Web Parts.

It is good that now developer has choice to choose which type of web parts they want to develop, in earlier developer has to create user control and then they can add that visual element in standard web parts, but now they can directly add visual elements with use of Visual Web Parts.

To take decision of using any web parts is based on the time and resource it requires and also many other parameters need to consider for business activity.

Monday, November 28, 2011

Connect office 365 SharePoint online with SharePoint client object model

When you create any SharePoint client object model application there are choices to connect with SharePoint either in LAN or SharePoint server. But now days there are much hype in office 365 provided by Microsoft, it does allow SharePoint online. You don’t need to manage your own SharePoint server if your organization is not much big and many companies are planning to move their work to office 365.

So it’s naturally necessary that your client object model should support this office 365 SharePoint online connection. Here there is a trick to connect with it, it’s not direct way to connect with SharePoint online. You need to consider many things for it like cookies and your id, password etc.

Here, it is very nicely explained how to authenticate with office 365 and make connection to SharePoint online with client object model.

Thursday, November 17, 2011

Calendar (datetime picker) type column in windows grid

Usually when we try to find some out of use column in default grid provided by .net, we are not able to do it. We require inheriting base class and then we need to put information inside of it.

Say for example, you require adding datetime picker column to your windows form grid, if you check all supported column types in grid, you won’t find such in it. We require writing custom code for it and then adding that columns in our grid control.

Here is some code for creating date time picker column, please make sure that you can add this code in separate component code and then you can access this column in whole project when ever needs.

using System;

using System.Windows.Forms;

public class CalendarColumn : DataGridViewColumn

{

public CalendarColumn() : base(new CalendarCell())

{

}

public override DataGridViewCell CellTemplate

{

get

{

return base.CellTemplate;

}

set

{

// Ensure that the cell used for the template is a CalendarCell.

if (value != null &&

!value.GetType().IsAssignableFrom(typeof(CalendarCell)))

{

throw new InvalidCastException("Must be a CalendarCell");

}

base.CellTemplate = value;

}

}

}

public class CalendarCell : DataGridViewTextBoxCell

{

public CalendarCell()

: base()

{

// Use the short date format.

this.Style.Format = "d";

}

public override void InitializeEditingControl(int rowIndex, object

initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)

{

// Set the value of the editing control to the current cell value.

base.InitializeEditingControl(rowIndex, initialFormattedValue,

dataGridViewCellStyle);

CalendarEditingControl ctl =

DataGridView.EditingControl as CalendarEditingControl;

// Use the default row value when Value property is null.

if (this.Value == null)

{

ctl.Value = (DateTime)this.DefaultNewRowValue;

}

else

{

ctl.Value = (DateTime)this.Value;

}

}

public override Type EditType

{

get

{

// Return the type of the editing control that CalendarCell uses.

return typeof(CalendarEditingControl);

}

}

public override Type ValueType

{

get

{

// Return the type of the value that CalendarCell contains.

return typeof(DateTime);

}

}

public override object DefaultNewRowValue

{

get

{

// Use the current date and time as the default value.

return DateTime.Now;

}

}

}

class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl

{

DataGridView dataGridView;

private bool valueChanged = false;

int rowIndex;

public CalendarEditingControl()

{

this.Format = DateTimePickerFormat.Short;

}

// Implements the IDataGridViewEditingControl.EditingControlFormattedValue

// property.

public object EditingControlFormattedValue

{

get

{

return this.Value.ToShortDateString();

}

set

{

if (value is String)

{

try

{

// This will throw an exception of the string is

// null, empty, or not in the format of a date.

this.Value = DateTime.Parse((String)value);

}

catch

{

// In the case of an exception, just use the

// default value so we're not left with a null

// value.

this.Value = DateTime.Now;

}

}

}

}

// Implements the

// IDataGridViewEditingControl.GetEditingControlFormattedValue method.

public object GetEditingControlFormattedValue(

DataGridViewDataErrorContexts context)

{

return EditingControlFormattedValue;

}

// Implements the

// IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.

public void ApplyCellStyleToEditingControl(

DataGridViewCellStyle dataGridViewCellStyle)

{

this.Font = dataGridViewCellStyle.Font;

this.CalendarForeColor = dataGridViewCellStyle.ForeColor;

this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;

}

// Implements the IDataGridViewEditingControl.EditingControlRowIndex

// property.

public int EditingControlRowIndex

{

get

{

return rowIndex;

}

set

{

rowIndex = value;

}

}

// Implements the IDataGridViewEditingControl.EditingControlWantsInputKey

// method.

public bool EditingControlWantsInputKey(

Keys key, bool dataGridViewWantsInputKey)

{

// Let the DateTimePicker handle the keys listed.

switch (key & Keys.KeyCode)

{

case Keys.Left:

case Keys.Up:

case Keys.Down:

case Keys.Right:

case Keys.Home:

case Keys.End:

case Keys.PageDown:

case Keys.PageUp:

return true;

default:

return !dataGridViewWantsInputKey;

}

}

// Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit

// method.

public void PrepareEditingControlForEdit(bool selectAll)

{

// No preparation needs to be done.

}

// Implements the IDataGridViewEditingControl

// .RepositionEditingControlOnValueChange property.

public bool RepositionEditingControlOnValueChange

{

get

{

return false;

}

}

// Implements the IDataGridViewEditingControl

// .EditingControlDataGridView property.

public DataGridView EditingControlDataGridView

{

get

{

return dataGridView;

}

set

{

dataGridView = value;

}

}

// Implements the IDataGridViewEditingControl

// .EditingControlValueChanged property.

public bool EditingControlValueChanged

{

get

{

return valueChanged;

}

set

{

valueChanged = value;

}

}

// Implements the IDataGridViewEditingControl

// .EditingPanelCursor property.

public Cursor EditingPanelCursor

{

get

{

return base.Cursor;

}

}

protected override void OnValueChanged(EventArgs eventargs)

{

// Notify the DataGridView that the contents of the cell

// have changed.

valueChanged = true;

this.EditingControlDataGridView.NotifyCurrentCellDirty(true);

base.OnValueChanged(eventargs);

}

}