Tuesday, August 25, 2009

Feature.xml and ItemEventReceiver.xml for Event Handler in WSS

If you are going to work with Microsoft Windows SharePoint Services event handler like Item Adding, Item Added and etc, create the following files to implelment it as a feature. Refer the below file contents.

Feature.xml




ItemEventReceiver.xml

Visual Studio.NET Debugging Tips and Tricks

Tip: Use the BreakPoints Window: If you know the name of the class and method you want to break on, you can choose New from the Breakpoints window and type it directly into the Function area of the window. Developers can spend 15 minutes wandering through their projects opening files just so they can position the cursor over a line of code and hit the F9 key to set a breakpoint. If you know the name of the class and method, doing it this way will find it and set the breakpoint. In addition, you can click it in the Breakpoints list of the window and go to the location automatically.

You can also set a breakpoint by just entering the method name, if it is unique in your application. And, if it isn't you will actually get a list of ALL the locations where the method can be found, which is extremely useful for setting multiple breakpoints on a commonly used function throughout your project. It also displays for overloaded methods in the same class.

Tip: Use Hit Counts: In the Breakpoints window, when you right-click and choose Properties and then click the Hit Counts button, you can modify a breakpoint with four possible combinations of choices. Experiment with this to see how useful it can be. What makes this especially useful is that when you have stopped in the Debugger, it tells you how many times your breakpoint has executed. You can also create conditional expressions that will trigger the debugger only if your expression evaluates to true or has changed since the last time it was evaluated.

Tip: Use Assertion Debugging: The idea behind asserts is very simple: When you are writing code, you understand that some condition is always expected to be true. If that condition is ever not true, then there is a bug. Asserts can be written so that if this condition is ever not true, the debugger will be launched at that exact point in your code:

System.Diagnostics.Debug.Assert (myValue >=0)

The nice thing about Assert windows is that they not only give you the opportunity to break or not, they also show you the stack trace at that point. A very powerful, yet highly under-utilized feature.

The file "http://servername/sites/Testing/test123/test.docx" is checked out or locked for editing by SHAREPOINT\system

Whenever you are trying to update the properies of an Item in ItemAdded Event of a Document Library. Need to use base.DisableEventFiring/base.EnableEventFiring before and after an item added. Refer the below sample source code for your further use,

Code Snippet:

public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
try
{
base.DisableEventFiring();
SPListItem oItem = properites.ListItem;
oItem["ItemName"] = "Testing";
oItem.SystemUpdate(false);
}
catch(Exception err)
{
Console.Write(err.Message);
}
finally
{
base.EnableEventFiring();
}
}

Useful SharePoint Tips Utility Pack

It specializes in Microsoft SharePoint technologies, including web parts, development, configuration, customization, and best practices for the use of Microsoft SharePoint Server and Windows SharePoint Services. It also provides some related Office Information, including VSTO and VSTA and other office application development tips. Please navigate the below URL for downlaod tool.


http://www.sharepoint-tips.com/2006/11/announcing-sharepoint-tips-utility-pack.html

STSADM Command Line Reference in WSS 3.0

Below you will find a listing of all the STSADM commands for Features and Solution,

Features:

installfeature

stsadm.exe -o installfeature
{-filename |
-name }
[-force]

uninstallfeature

stsadm.exe -o uninstallfeature
{-filename |
-name |
-id }
[-force]

activatefeature

stsadm.exe -o activatefeature
{-filename |
-name |
-id }
[-url ]
[-force]

deactivatefeature

stsadm.exe -o deactivatefeature
{-filename |
-name |
-id }
[-url ]
[-force]

scanforfeatures

stsadm.exe -o scanforfeatures
[-solutionid ]
[-displayonly]

Solution:

addsolution

stsadm.exe -o addsolution
-filename
[-lcid ]

deletesolution

stsadm.exe -o deletesolution
-name
[-override]
[-lcid ]

deploysolution

stsadm.exe -o deploysolution
-name
[-url ]
[-allcontenturls]
[-time

What is the difference between Convert.toString and .toString() in C#

Just to give an understanding of what the above question means seethe below code.

int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));

We can convert the integer "i" using "i.ToString()" or "Convert.ToString" so what’s the difference. The basic difference between them is “Convert” function handles NULLS while "i.ToString()" does not it will throw a NULL reference exception error. So as good coding practice using "convert" is always safe.

Monday, August 24, 2009

Enable Data Column readonly properties false in DataTable in C#

When you are getting data from Data Access Layer(DAL) as a DataTable. Here the particular Data Column readonly property is sets a TRUE. Suppose you want to update new values within the Data Column, use the below source code in C#.

public static DataTable CreateDataTable(DataTable dt)
{
foreach (DataRow dr in dt.Rows)
{
dt.Columns["Column Name"].ReadOnly = true;
dr.BeginEdit();
dr["Column Name"] = "New Value";
dr.EndEdit();
if (dr.RowState == DataRowState.Modified)
{ dr.AcceptChanges(); }
}
return dt;
}

.NET Reflector

.NET Reflector enables you to easily view, navigate, and search through, the class hierarchies of .NET assemblies, even if you don't have the code for them. With it, you can decompile and analyze .NET assemblies in C#, Visual Basic, and IL.

Refer this URL for download the .NET Refelector tool.

http://www.red-gate.com/products/reflector/

Wednesday, August 19, 2009

Disabling submit Aspx button in C# .net

Following are simple ways to make a button disabled and fire the click event of the button in code behind .aspx file. Add this code in Page_Load event.

btnSubmitPay.Attributes.Add("OnClick", "this.disabled=true;return true;");

btnSubmitPay.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;" + GetPostBackEventReference(btnSubmitPay));

btnSubmit.Attributes.Item("onclick") = "this.disabled=true;" & GetPostBackEventReference(btnSubmit).ToString();

aspxcallbackpanel and combobox in DevXpress controls

protected void Page_Load(object sender, EventArgs e) {
if(!IsCallback)
FillCombo(!IsPostBack);
}

protected void FillCombo(bool initSelectedIndex)
{
ASPxComboBox2.Items.Clear();
for(int i = 0; i < 3; i++) {
ASPxComboBox2.Items.Add(ASPxComboBox1.Value.ToString() + i.ToString());
}
if(initSelectedIndex)
ASPxComboBox2.SelectedIndex = 0;
}

protected void ASPxCallbackPanel1_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) {
FillCombo(true);
}