Thursday, September 24, 2009

Assembly ‘X’ could not be uninstalled because it is required by another application

Remove the keys from following location in registry then you can now uninstall them from the GAC.

Step 1:
Goto - Start - Run -Regedit

Step 2:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\Global

Step 3 :
delete the class name as in assembly

Step 4:
Uninstall from assembly

Friday, September 18, 2009

Naming Conventions for .NET / C# Projects

Reference URL :

http://www.akadia.com/services/naming_conventions.html

Capitalization Styles Defined

We define three types of capitalization styles:

Pascal case

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

Example:

BackColor, DataSet

Camel case

The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.

Example:

numberOfDays, isValid

Uppercase

All letters in the identifier are capitalized.

Example:

ID, PI

Hungarian Type Notation Defined

Hungarian notation is any of a variety of standards for organizing a computer program by selecting a schema for naming your variables so that their type is readily available to someone familiar with the notation. It is in fact a commenting technique.

Example:

strFirstName, iNumberOfDays

There are different opinions about using this kind of type notation in programming nowadays. Some say that it’s useful, and it should be used everywhere to enhance clarity of your code. Others say it just obfuscates your code, because it has no real advantage in modern programming environments.

Our point of view is a moderated one: use it wisely, meaning, we only use Hungarian notation for private or local variables, that are only accessible and interesting to the programmer of the class.

Don’t use it with public variables, properties or parameters in methods, because they are exposed to the outside world. Someone who uses your classes and accesses properties of your class, is not interested in type, but just wants to use them.

In the .NET framework, there are a lot of types, so we extended and adapted the Hungarian notation with our own type notation.

Naming Guidelines

1). Private Variables (Fields in C#) Naming Guidelines

Naming guidelines

Prefix private variables with a "_" and Hungarian-style notation.

Case guidelines

Use camel case as a general rule, or uppercase for very small words

Example:

_strFirstName, _dsetEmployees

// Field
private OleDbConnection _connection;

// Property
public OleDbConnection Connection
{
get { return _connection; }
set { _connection = value; }
}

2). Local Variables Naming Guidelines

Naming guidelines

Prefix private or local variables with Hungarian-style notation.

Case guidelines

Use camel case as a general rule, or uppercase for very small words

Example:

strFirstName, dsetEmployees

3). Namespace Naming Guidelines

Naming guidelines

The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows:

CompanyName.TechnologyName[.Feature][.Design]

Prefixing namespace names with a company name or other well-established brand avoids the possibility of two published namespaces having the same name. Use a stable, recognized technology name at the second level of a hierarchical name.

Example:

Akadia.Traffic, System.Web.UI, System.Windows.Forms

Case guidelines

Use Pascal case as a general rule, or uppercase for very small words.

Example:

System.Windows.Forms, System.Web.UI

4). Class Naming Guidelines

Naming guidelines

Use a noun or noun phrase to name a class.
Do not use a type prefix, such as C for class, on a class name.
Do not use the underscore character (_).

Case guidelines

Use Pascal case. Example:

FileStream, Button

5). Interface Naming Guidelines

Naming guidelines

Prefix interface names with the letter "I", to indicate that the type is an interface.
Do not use the underscore character (_).

Case guidelines

Use Pascal case. Example:

IServiceProvider, IFormatable

6). Parameter Naming Guidelines

Naming guidelines

Use descriptive parameter names. Parameter names should be descriptive enough that the name of the parameter and its type can be used to determine its meaning in most scenarios. To distinguish parameters from other variables the prefix "p" should be used.

Do not prefix parameter names with Hungarian type notation.

Do not use a prefix for parameter names of an event handler and exceptions.

Case guidelines

Use camel case. Example:

pTypeName, pNumberOfItems

7). Method Naming Guidelines

Naming guidelines

Use verbs or verb phrases to name methods.

Case guidelines

Use Pascal case. Example:

RemoveAll(), GetCharAt()

8). Property / Enumerations Naming Guidelines

Naming guidelines

Use a noun or noun phrase to name properties.
Do not use Hungarian notation.

Case guidelines

Use Pascal case. Example:

BackColor, NumberOfItems

9). Event Naming Guidelines

Naming guidelines

Use an EventHandler suffix on event handler names.

Specify two parameters named sender and e. The sender parameter represents the object that raised the event. The sender parameter is always of type object, even if it is possible to use a more specific type. The state associated with the event is encapsulated in an instance of an event class named "e". Use an appropriate and specific event class for the e parameter type.

Name an event argument class with the EventArgs suffix.

Case guidelines

Use Pascal case. Example:

public delegate void MouseEventHandler(object sender, MouseEventArgs e);

9). Exception Naming Guidelines

Naming guidelines

Event handlers in Visual Studio .NET tend to use an "e" parameter for the event parameter to the call. To ensure we avoid a conflict, we will use "ex" as a standard variable name for an Exception object.

Example

catch (Exception ex)
{
// Handle Exception
}

10). Constant Naming Guidelines

The names of variables declared class constants should be all uppercase with words separated by underscores. It is recommended to use a grouping naming schema.

Example (for group AP_WIN):

AP_WIN_MIN_WIDTH, AP_WIN_MAX_WIDTH, AP_WIN_MIN_HIGHT, AP_WIN_MAX_HIGHT

11). C# Primitive Type Notation

sbyte sy
short s
int i
long l
byte y
ushort us
uint ui
ulong ul
float f
double d
decimal dec
bool b
char c

12). Visual Control Type Notation

Assembly asm
Boolean bln
Button btn
Char ch
CheckBox cbx
ComboBox cmb
Container ctr
DataColumn dcol
DataGrid dgrid
DataGridDateTimePickerColumn dgdtpc
DataGridTableStyle dgts
DataGridTextBoxColumn dgtbc
DataReader dreader
DataRow drow
DataSet dset
DataTable dtable
DateTime date
Dialog dialog
DialogResult dr
Double dbl
Exception ex
GroupBox gbx
HashTable htbl
ImageList iml
Integer int
Label lbl
ListBox lbx
ListView lv
MarshallByRefObject rmt
Mainmenu mm
MenuItem mi
MDI-Frame frame
MDI-Sheet sheet
NumericUpDown nud
Panel pnl
PictureBox pbx
RadioButton rbtn
SDI-Form form
SqlCommand sqlcom
SqlCommandBuilder sqlcomb
SqlConnection sqlcon
SqlDataAdapter sqlda
StatusBar stb
String str
StringBuilder strb
TabControl tabctrl
TabPage tabpage
TextBox tbx
ToolBar tbr
ToolBarButton tbb
Timer tmr
UserControl usr
WindowsPrincipal wpl

Wednesday, September 16, 2009

Downloading xml data from web server and reading in C#

Help URL: http://msdn.microsoft.com/fr-fr/library/system.net.webresponse.getresponsestream(VS.80).aspx

// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create("http://phoenixswsolutions.com/app.xml");

//Credentials for accessing the information
myWebRequest.Credentails = System.Net.CredentailsCache.DeafultCredentails;

// Send the 'WebRequest' and wait for response.WebResponse myWebResponse = myWebRequest.GetResponse();

// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( ReceiveStream, encode );

string strResponse=readStream.ReadToEnd();

Console.WriteLine(strResponse);

readStream.Close();

// Release the resources of response object.myWebResponse.Close();

Monday, September 14, 2009

Creating Custom Editor Part for Sharepoint Webpart

Referred from URL:
http://sharepointconsultant.blogspot.com/2009/04/creating-custom-editor-part-for.html

What is Editor part and why do we need them?
Well for this question to answer, basically all webparts will have a property pane when we select modify this webpart. This tool/property pane allows to set properties to webparts.

Now what if we need to customize this property pane? Say client needs to have a set of controls where user can select values from these controls which inturn feeds to webpart, so that webpart takes these properties changes.

Let me give you an example,

I am writing a editor part which has couple of dropdownlists. These drop down list will get infomration from differetn field values from from list/document library. Now user can select the required values/fields in the dropdownlist, and webpart will take these values.

So without wasting any moments,
lets get the ground running,

1. Create a webpart in a normal mode with all web browasable properties and get this up & running.
2. Once it is ok, now to appreciate the purpose of editor part,

3. create a class inherting EditorPart. You can see this class as a normal webpart. Here you need to create controls to be rendered by using same old createchildcontrols, RenderContents and so on.

4. Now there are two methods which you need to take a bit care.

(*) Applychanges
(*) SyncChanges

Applychanges is the method which takes all the information from the editor part controls/properties and passes it to WebPart in question's Property.
SyncChanges - as name signifies, it synchronies the values between Editor Part and Webpart.

Now Lastly, in the webpart class, override EditorPart method basically creates a object of your custom editor part and sends it to webpart manager/framework. Basically this method tells that when ever a users click on modify this webpart, then instead of displaying a normal property panel create a custom property panel with this object. One more caveat is that, make all webbrowsable property false in the webpart.

Below is the code for EditorPart,


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace kiran.webparts
{
class MyEditorPart :EditorPart
{
private TextBox txtbx;
private Button btnClick;
private CustomControls.SearchControl srcCntrl;
protected override void CreateChildControls()
{
// base.CreateChildControls();
this.Controls.Add(txtbx);
//this.Controls.Add(btnClick);
this.Controls.Add(srcCntrl);
}
public MyEditorPart()
{
this.ID = "MyEditorpart";
txtbx = new TextBox();
btnClick = new Button();
srcCntrl = new CustomControls.SearchControl();
btnClick.Click += new EventHandler(btnClick_Click);
}
void btnClick_Click(object sender, EventArgs e)
{
}
public override bool ApplyChanges()
{
((WebpartWithEditorPart)WebPartToEdit).Phone = txtbx.Text;
return true;
}
public override void SyncChanges()
{
txtbx.Text = ((WebpartWithEditorPart)WebPartToEdit).Phone;
}
protected override void Render(HtmlTextWriter writer)
{
txtbx.RenderControl(writer);
btnClick.RenderControl(writer);
srcCntrl.RenderControl(writer);
}
protected override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
}
}
}

Below is the code for Webpart in question.


using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace kiran.webparts
{
[Guid("71c2ac74-6ffa-4159-b6ed-7807335fd093")]
public class WebpartWithEditorPart : System.Web.UI.WebControls.WebParts.WebPart
{
public WebpartWithEditorPart()
{
}
TextBox txtbx;
Button btn;
string m_phone;
[Personalizable(PersonalizationScope.Shared), WebBrowsable(false),WebDisplayName("Phone"),WebDescription("Phone number")]
public string Phone
{
get { return m_phone; }
set { m_phone = value; }
}
protected override void CreateChildControls()
{
base.CreateChildControls();
txtbx = new TextBox();
btn = new Button();
btn.Click += new EventHandler(btn_Click);
this.Controls.Add(txtbx);
this.Controls.Add(btn);
}
void btn_Click(object sender, EventArgs e)
{
txtbx.Text = "Value from the property is " + Phone;
}
public override EditorPartCollection CreateEditorParts()
{
//return base.CreateEditorParts();
ArrayList alist = new ArrayList();

MyEditorPart myeditorpart = new MyEditorPart();
myeditorpart.ID = this.ID + "_EditorPart";
myeditorpart.Title = "Phone Number";
myeditorpart.GroupingText = "";
alist.Add(myeditorpart);
EditorPartCollection EdPartColl = new EditorPartCollection(alist);
return EdPartColl;
}
}
}

Friday, September 11, 2009

Running operating system inside a Virtual PC with specific date/time

Manually change the .vmc file:

The .vmc files contain the configuration of each virtual machine.

You have to make 2 changes in the right .vmc file:
A. Disable the time synchronization:
Under the following mouse configuration:

true

Add this:falseB. Set the desired date/time:You have to find the time_bytes value inside the .vmc file, which looks like this one:27003200110001201008After finding it, set the desired date/time value according to the following specification:Digits 1 - 2 contain the seconds value.Digits 5 - 6 contain the minutes value.Digits 9 - 10 contain the hours value.Digits 15 - 16 contain the day value.Digits 17 - 18 contain the month value.Digits 19 - 20 contain the year value.In the above example, the date/time value is 11:32:27, 20/10/2008After making the above 2 changes, save the .vmc file, and the guest operating system will start in the same date/time that you set in the time_bytes value.