Sunday 31 August 2008

Installing Sharepoint Services 3.0 on Windows Vista OS

Just few days back I started exploring Sharepoint Technologies, and started thinking where to start. The biggest setback for me was I cannot run Sharepoint Services on my windows Vista System because Sharepoint Services can only be installed on Windows Server Family of Operating System. But now I cannot go back and repartition my System and install Sharepoint, I also tried using Windows Virtual Machine, but Windows Server 2003 was not working properly on my Windows Virtual Machine.

So now I am left with only two option either repartition the whole harddisk and install dual boot OS or Find some way to run windows sharepoint services on my windows vista. So I started googling and finally I found a jackpot where I can install sharepoint on Windows Vista. First I thought its one more bluff, but thought to give a try, and it worked, and now I am using Windows Sharepoint Services on my Windows Vista Ultimate OS.

Just follow the link below which will guide you step by step process how to do that.

http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx

To download the setup helper file you can either download from the above link or you can download from here directly.

Cheers

~Brij
Share:

Friday 29 August 2008

Refreshing the Data in ObjectDataSource Dynamically

In my previous post, you have seen the paging example, but there is one small problem you may face, if you are using ControlParameter or QueryStringParameter, for instance take a scenario when you are using ASP.NET AJAX and you have GridView and Search button in update panel.

On page load, the ObjectDataSource will take the default parameters from the DropDownList and QueryString, but problems comes when we want to click Search Button to get the changed values of the DropDownList or the QueryString without posting the page again.

Generally to refresh the data of ObjectDataSource you often write

ObjectDataSource1.Select();

On Click of Search Button.

But hold on this is only good if you want to see the changed data from the database or Rebind the ObjectDataSource, but this will not pass the current value from the controls or query string as a parameter to the database Query or Procedure. Resulting in which you will keep getting the existing query result only, so here is the actual code below for which I have written such a big story.

GridView1.DataBind();

Yes just one line code, don't worry this internally calls the ObjectDataSource1.Select(), but will give you the desired result, I hope this will help you.

Thanks

~Brij
Share:

ASP.NET Custom Paging with GridView using ObjectDataSource

Paging is perhaps one of the most required in data presentation, specially when it comes to huge amount of data, normal paging becomes nightmare. If you are developing your application using ASP.NET 2.0, then you can make use of ObjectDataSource in a very efficient manner to achieve paging.

The code which I am providing below will give you a complete understanding of how you can do this, this technique will fetch one the number of data which you set in PageSIze of GridView from the DataBase, instead of fetching entire data and on every PageIndexChanged event repeating the full cycle again,

First you need to either modify or write your procedure the input and output parameters which will fit into your .NET code to get the paging.

create procedure proc_EmployeeDetails
@empId int,
@empStatus varchar(10),
@pagestart int = null,
@pagesize int = null,
@numresults int output
as

create table #empresults
(
[rowid] [int] IDENTITY (1, 1) NOT NULL,
[empID] [nchar] (5) ,
[EmpName] [nvarchar] (30),
[Address] [varchar] (200),
[DOB] [datetime],
[Age] [int],
)


insert into #empresults (empid, empname, address, DOB, Age)
select empID, EmpName, Address, DOB, Age
where
empid = @empId AND empStatus = @empStatus
order by EmpName

set @numresults = @@rowcount

if @pagesize is null
set @pagesize = @numresults

if @pagestart is null
set @pagestart = 1

set rowcount @pagesize

select *
from #empresults
where rowid >= @pagestart

drop table #tempresults





Next I create a Employee class which will hold the results from the database.




public class EmployeeCollection : IList<Employee> { }

public class Employee
{
private int _empId;
private string _empName;
private DateTime? _DOB;
private int _age;
private string _address;

public Employee() { }

public int EmployeeId
{
get { return _empId; }
set { _empId = value; }
}

public string EmployeeName
{
get { return _empName; }
set { _empName = value; }
}

public DateTime? DOB
{
get { return _DOB; }
set { _DOB = value; }
}

public int Age
{
get { return _age; }
set { _age = value; }
}

public string Address
{
get { return _address; }
set { _address = value; }
}

}





Now as we have got the BusinessObjects, it time to create a class specifically designed to handle request from ObjectDataSource. This class you can keep in your app_code directory of web project and is used like facade layer between UI layer and Business Layer.




Excuses for the code formatting, but you got the idea what I mean to say, right ?




public class EmployeeDataSource
{
public EmployeeDataSource() { }

public int SelectCount(int empId, string employeeStatus, ObjectDataSourceSelectingEventArgs e)
{
return e.Arguments.TotalRowCount;
}

public EmployeeCollection Select(int empId, string employeeStatus, int maximumRows, int startRowIndex, ObjectDataSourceSelectingEventArgs e)
{
using (SqlConnection connection = new SqlConnection("Initial Catalog=Employee;Integrated Security=SSPI;Data Source=."))
using (SqlCommand command = new SqlCommand("proc_EmployeeDetails", connection))
{
connection.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@empId", empId);
command.Parameters.AddWithValue("@empStatus", employeeStatus);
command.Parameters.AddWithValue("@pagestart", startRowIndex);
command.Parameters.AddWithValue("@pagesize", maximumRows);
command.Parameters.Add(new SqlParameter("@numresults", SqlDbType.Int, 0, ParameterDirection.Output, false, 0, 0, null, DataRowVersion.Default, 0));
EmployeeCollection employees = new EmployeeCollection();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Employee emp = new Employee();
emp.EmployeeId = reader.GetInt32("empId");
emp.EmployeeName = reader.GetString("empname");
emp.DOB = reader.GetDateTime("DOB");
emp.Age = reader.GetInt32("Age");
emp.Address = reader.GetString("Address");
employees.Add(emp);
}
}
e.Arguments.TotalRowCount = (int)command.Parameters["@numresults"].Value;
return employees;
}
}





Now I am adding code to the code behind of the EmployeeDetails.aspx page.



protected void objectDataSourceOrders_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
if (!e.ExecutingSelectCount)
{
e.Arguments.MaximumRows = this.gridViewEmployees.PageSize;
e.InputParameters.Add("e", e);
}
}

Here is the ASPX page code that goes along with the rest of this example




<body>
<
form id="form1" runat="server">
<
div>
<
asp:DropDownList ID="ddlEmpStatus" runat="server">
<
asp:ListItem Text="Active" Value="Active" Selected="True"></asp:ListItem>
<
asp:ListItem Text="Disabled" Value="Disabled"></asp:ListItem>
</
asp:DropDownList>
</
div>
<
div>
<
asp:GridView ID="gridViewEmployees" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="2" DataSourceID="objectDataSourceEmployee" ForeColor="Black" GridLines="None" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px">
<
FooterStyle BackColor="Tan" />
<
Columns>
<
asp:BoundField DataField="EmployeeId" HeaderText="ProductId" SortExpression="ProductId" />
<
asp:BoundField DataField="EmployeeName" HeaderText="ProductName" SortExpression="ProductName" />
<
asp:BoundField DataField="DOB" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<
asp:BoundField DataField="Age" HeaderText="CustomerId" SortExpression="CustomerId" />
<
asp:BoundField DataField="Address" HeaderText="OrderId" SortExpression="OrderId" />
</
Columns>
<
SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<
PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<
HeaderStyle BackColor="Tan" Font-Bold="True" />
<
AlternatingRowStyle BackColor="PaleGoldenrod" />
</
asp:GridView>
<
asp:ObjectDataSource ID="objectDataSourceEmployee" runat="server" EnablePaging="True"
SelectMethod="Select" TypeName="EmployeeDataSource" OnSelecting="objectDataSourceOrders_Selecting" SelectCountMethod="SelectCount">
<
SelectParameters >
<
asp:QueryStringParameter QueryStringField="empid" DefaultValue="0" Name="empId" />
<
asp:ControlParameter ControlID="ddlEmpStatus" DefaultValue="Active" Name="employeeStatus" PropertyName="Value" />
</
SelectParameters>
</
asp:ObjectDataSource></div>
</
form>
</
body>


In the aspx page I am passing the Query string and dropdown control value as a parameter, and Binding the result to the GridView.





The code above worked for me, I hope you too find this code useful.





Thanks


~Brij
Share:

Tuesday 19 August 2008

Versioning ASP.NET 2.0 WebSite Assembly / Web Deployment Project

The web project model changed in number of ways from Visual Studio 2003 to Visual Studio 2005, But one major part which is missing is the ability to version the assembly using AssemblyInfo.cs file.

This is because the model of VS 2005 dynamically creates multiple assemblies for each class file. Resulting in which we cannot have single named assembly to set version number.

We cannot change the default behaviour of compilation but we can change the way we can deploy our project files and assemblies, by using Web Deployment Project.

Microsoft Web Deployment Project adds numerous features which nicely integrates with Visual Studio 2005, out of which the most useful I found is:

More control over number of assemblies generated by a pre-complied web application as well as control over the naming of the output assemblies. Which means you can generate either single assembly for you entire project, and select the name and version you want for e.g Foo.dll, etc or generate the assemblies per directory/ pages or control.

The ability to customize and modify the web.config file during deployment, that means you need not to change you web.config file every time before making release or deploying the project, instead you can specify the web.config keys on Web Deployment project, that you use for deployment, like this you can customize any other web.config settings also.

These are the few things which I named here, if you want more information on how to install, and use this you can visit the Scott's Blog from the below link:

http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx

Or you can Download the VS 2005 Web Deployment Project from

WebDeploymentSetup.msi

Other Useful Links which may help you to further explore this subject

http://msdn.microsoft.com/en-us/library/aa479568.aspx

Web Deployment Projects Forum

I hope this will help you, if you have something to share on this topic, then please leave a comment.

Thanks

~Brij

Share:

Tuesday 12 August 2008

IsNumeric Function in C#

VB.NET has lots of functions that C# developers have to create manually.

Out of which I am providing here the different alternatives of IsNumeric function of VB.NET in C#

Using Parse

static bool IsNumeric(string s)

{

    try

    {

        Int32.Parse(s);

    }

    catch

    {

        return false;

    }

    return true;

}

Using Double.TryParse

(C# 2.0 and above)

static bool IsNumeric(object expression)

{

    if (expression == null)

        return false;

    double number;

    return Double.TryParse(Convert.ToString(expression,   CultureInfo.InvariantCulture),

        System.Globalization.NumberStyles.Any, NumberFormatInfo.InvariantInfo, out number);

}

Using Regular Expression

bool IsNumeric(string value)

{

    Regex regxNumericPatters = new Regex("[^0-9]");

    return !regxNumericPatters.IsMatch(value);

}

OR

static bool IsNumeric(string inputString)

{

    return Regex.IsMatch(inputString, "^[0-9]+$");

}

Using Char

static bool IsNumeric(string numberString)

{

    foreach (char c in numberString)

    {

        if (!char.IsNumber(c))

        return false;

    }

    return true;

}

I hope this will help you, if you have more ideas then do write comments.

Share:

Sunday 3 August 2008

Using ASP.NET 3.5 History Control with ASP.NET 2.0

Using Back Button in ASP.NET 2.0 and AJAX
This post will show you how to use ASP.NET 3.5 Ajax COntrolToolKit History control with ASP.NET 2.0,

As you might be aware of that microsoft has included AJAX with Framework 3.0, and from version 3.5 microsoft has also included History control in his AJAX Control toolkit,

Using history control we can use browser back button to navigate backwards in the pages containing AJAX Controls, which was normally not possible till Framework 2.0.

But if you are still using ASP.NET 2.0, then don't get disappointed you can use the same control in ASP.NET 2.0, remember to use this you don't need to install Framework 3.0, or 3.5.

You just need to do the steps given below:


1. Download the DLL, Microsoft.Web.Preview.dll, version 1.1.61025.0 or alrernatively download the source code from here and copy the DLL from bin folder.

2. From the Toolbox of you project, right click and Select Choose Items...

3. Locate the Microsoft.Web.Preview.dll and select OK.

4. You can find see the following tiems in the screenshot below, are added in your toolbox.

5. Now add the code below in your web.config
<
sectionGroup name="microsoft.web.preview"
type="Microsoft.Web.Preview.Configuration.PreviewSectionGroup, Microsoft.Web.Preview">
<
section name="search"
type="Microsoft.Web.Preview.Configuration.SearchSection, Microsoft.Web.Preview"
requirePermission="false" allowDefinition="MachineToApplication"/>
<
section name="searchSiteMap"
type="Microsoft.Web.Preview.Configuration.SearchSiteMapSection, Microsoft.Web.Preview"
requirePermission="false" allowDefinition="MachineToApplication"/>
<
section name="diagnostics"
type="Microsoft.Web.Preview.Configuration.DiagnosticsSection, Microsoft.Web.Preview"
requirePermission="false" allowDefinition="MachineToApplication"/>

</

sectionGroup>
6. Once you are done with this, open the webpage where you want to use the history control, and add the code below.

<

asp:History ID="History1" runat="server" OnNavigate="History1_Navigate">

</asp:History>

7. Open the codebehind and add the following piece of code

protected

void History1_Navigate(object sender, Microsoft.Web.Preview.UI.Controls.HistoryEventArgs args)

{

int startPage = 0;

if (args.State.ContainsKey("StartPage"))

{

startPage = (

int)args.State["StartPage"];

}

GridView1.PageIndex = startPage;

}

protected

void GridView1_PageIndexChanged(object sender, EventArgs e)

{

History1.AddHistoryPoint(

"StartPage", ((GridView)sender).PageIndex);

}

And thats it!!! You are ready to go...

This code uses GridView Paging, to demonstrate the HistoryControl

You can download the running sample from the here, C# Code, VB.NET Code

You can also refer my previous post

Using ASP.NET 3.5 Extensions History Control for complete Samples and Videos.

Sorry for the my code formatting, I tried to explain the steps, I hope this will help you.

Share: