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

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

}

}