Wednesday, August 13, 2008

Localization in flex

1) compile the application with the following compiler options
-locale= -resource-bundle-list myres.txt

Now myres.txt will be created in the bin directory.

2) Create the resource swf file using the following command.
mxmlc -locale=en_US -source-path+=locale/{locale} -include-resource-bundles={contents of myres.txt} -output en_US_ResourceModule.swf

The output swf should have the format {locale string}_ResourceModule.swf.

Tuesday, August 12, 2008

Calling PHP page in Flex and binding to combobox

using HTTPService components, you can call php page. The php page response to flex, sends the result in the form of xml.

E.g.,

1) Use this code to call a php page
mx:httpservice id="xmlRPC" url="http://localhost/PHP/GetCountry.php" />

2) Use this code to bind the result to combobox:
mx:combobox id="Country" prompt="Select" width="210" y="177" x="125" dataprovider="{xmlRPC.lastResult.Country.CountryDetails}" labelfield="CountryCode"/>

The GetCountry.php response should be like this:

country>
countrydetails>
countrycode>US
/countrydetails>
countrydetails>
countrycode>IN
/countrydetails>
/country>

TypeError: Error #1009: Cannot access a property or method of a null object reference.

This error usually gets, when some changes had made to project properties.
for e.g., changing compiler settings from locale en-US to locale.

When applying localization like this validation controls will not work in flex.

To make this work, do not change any settings in project properties.

Passing data with URL in flex

1) Include creationComplete="init(event);" in mx:Application

2) Include this script in mx:script tag
import mx.managers.BrowserManager;
import mx.managers.IBrowserManager;
import mx.utils.URLUtil;

private var bm:IBrowserManager;
[Bindable]
private var fName:String;
[Bindable]
private var lName:String;

private function init(e:Event):void {
bm = BrowserManager.getInstance();
bm.init("", "Welcome!");

/* The following code will parse a URL that passes firstName and lastName as
query string parameters after the "#" sign; for example:
http://www.mydomain.com/MyApp.html#firstName=Nick&lastName=Danger */
var o:Object = URLUtil.stringToObject(bm.fragment, "&");
fName = o.firstName;
lName = o.lastName;
}
]]>

3) use fName and lName with the text property of any control. for e.g.,
mx:Label text ={fName}

Thursday, August 7, 2008

Corner radius property in flex

To make the corner radius property for any layput control to work, first you need to set the borderstyle property to solid then,
it is possible to see the rounded corners for a layout.

Wednesday, July 30, 2008

Project Server 2007 Configuration

1) To access Project Professional 2007

Goto Server settings->EnterPrise Global->Click Configure Project Professional
To create a new project : Project -> Proposals and Activities -> Click on New -> Activity
Enter project Name, Description and Work Order Number = 74250 ( a valid one in Internap Web site)
Now Press Save and in the Grind View click on 'Build Team'.
Add a user and press 'Save'
Click on 'Resource Plan' -> Build Team -> Select User and Add him
Press Save and Close
Add Task(s) and press 'Save and Publish' To add a resource.

2) To add a resource:

Go to the Resources->Resource Center in the left frame.
Go to New->Resources
Enter all the details and click save.

Repeat the above steps to add more resources.

3) To add a Project:

Go to the Projects ->Proposals and Activities in the left frame.
Click New->Activities. Enter the Project name and project details, click Save and then Click Save and publish button

Repeat the above steps to add more projects.

4) To add the Resources to the Project

Select the newly created Project and click Build Team button.
Select the Resource name and click Add button.
Click Save button.
Now click cancel button to come back to previous page.

Repeat the above steps to add more

5) To create a new task

Click on newly created project name->navigates to the task list page.
Enter the task and assign the task to the resources under the Resource plan column.
Click Save button and then click Save and Publish button.
Click Close button to go back to project page.

Repeat the above steps to add more

6) To publish resource plan for a project

Select Project Name, click Resource Plan link, Select the Resource name and click Add button.
Click Save button.and Save and publish button, click close button to go back to main page.

Repeat the above steps to add more.

7) To see the configured projects

1. Projects->Project Center-> Click on the project name (e.g. Virtualization) : This will show the project plan as shown in MS Project.
2. Double clicking on the project icon will show the work details.


8) To delete a project, go to Server Settings->Delete Enterprise Objects ->Select the Project

9) To Define a mandatory field for a project, goto Server Settings -> Enterprise Custom Field Definition ->New Field ->Enter Name -> select Entity(Project) ->Select Type(like Number or Text)-> Required Can be checked if that field has to be mandatory -> Click Save

Tuesday, July 29, 2008

Upgrade from a trial version of Office SharePoint Server 2007

Use the following procedure to convert a license type and enter the product key.
Convert a license type and enter the product key

1.In Central Administration, on the top link bar, click Operations.
2.On the Operations page, in the Upgrade and Migration section, click Convert license type.
3.On the Convert License Type page, in the Enter the Product Key box, type the new product key.

Reffer: http://technet.microsoft.com/en-us/library/cc263204.aspx

Sunday, July 27, 2008

How to checkout in SubVersion?

1) Create the repository using svnadmin command as follows
svnadmin create --fs-type fsfs C:\SVN

2) Change directory to newly created repository as follows
cd C:\SVN

3) Checkout the directory using svn command as follows.
svn checkout file:///C:/SVN C:\Test

Thus, your working directory C:\Test is checked out to the repositoy C:\SVN.

Friday, July 18, 2008

Unable to browse the website after hosting in IIS 6.0

To help minimize the attack surface of the server, IIS 6.0 is not installed on Windows Server 2003 by default. When you first install IIS 6.0, it is locked down
— which means that only request handling for static Web pages is enabled, and only the World Wide Web Publishing Service (WWW service) is installed. None of the features that sit on top of IIS are turned on, including ASP, ASP.NET, CGI scripting, FrontPage® 2002 Server Extensions from Microsoft, and WebDAV publishing. If you do not enable these features, IIS returns a 404 error.  

1.In IIS Manager, click the Web Service Extensions folder.
2.In the details pane, select the Web service extension that you want to enable, and then click Allow.
3.To see the properties of a Web service extension, select an extension, and then click Properties.

Please see below, how to enable web service extention.

Thursday, July 17, 2008

Trial Period Expired Error in Project Server

Try the following 2 approaches to Upgrade from a trial version of Office SharePoint Server 2007,

Approach 1:

Found in http://technet.microsoft.com/en-us/library/cc263204.aspx

Use the following procedure to convert a license type and enter the product key.
Convert a license type and enter the product key

1. In Central Administration, on the top link bar, click Operations.
2. On the Operations page, in the Upgrade and Migration section, click Convert license type.
3. On the Convert License Type page, in the Enter the Product Key box, type the new product key.

Approach 2:

Re-run the "SharePoint Products and Technologies Configuration Wizard",
Found in http://www.eggheadcafe.com/software/aspnet/29540531/trial-period-expired-me.aspx

Binding images using Embeded Resource in ASP.Net, C#

Follow the simple 5 steps to make use of Emebeded Resource in .Net

Step 1: Open a new project, select windows application and click ok.

Step 2: Right click on the Solution, click on add existing item, and add all the images you want to bind.
Now, go to the each image property and select Embedded Resource as Build Action.

Step 3: Add the following code in Form behind class.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace EmbededResource
{
public partial class Form1 : Form
{

ArrayList pics;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.PictureBox pBox;
private System.Windows.Forms.Button btnDisplay;
public Form1()
{
InitializeComponent();
pics = new ArrayList();

}

private void Form1_Load(object sender, EventArgs e)
{
Stream imgStream = null;
Bitmap bmp = null;

// get a reference to the current assembly
Assembly a = Assembly.GetExecutingAssembly();

string[] resNames = a.GetManifestResourceNames();

foreach (string s in resNames)
{
//txtInfo.Text += s + "\r\n";
if (s.EndsWith("jpg"))
{
// attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStream(s);
if (!(null == imgStream))
{
// create a new bitmap from this stream and
// add it to the arraylist
bmp = Bitmap.FromStream(imgStream) as Bitmap;

if (!(null == bmp))
{
pics.Add(bmp);
}
bmp = null;
imgStream.Close();
imgStream = null;
}
}
}

}

private void pBox_Click(object sender, EventArgs e)
{
Random generator = new Random();
Bitmap bmp = pics[generator.Next(pics.Count)] as Bitmap;
if (!(null == bmp))
{
pBox.Image = bmp;

}
bmp = null;
generator = null;
}

private void pBox_DoubleClick(object sender, EventArgs e)
{
this.Close();
}

}
}

Step 4: Go to the defination of InitializeComponent() and add the foolowing code

private void InitializeComponent()
{
this.pBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pBox)).BeginInit();
this.SuspendLayout();

this.pBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pBox.Location = new System.Drawing.Point(8, 8);
this.pBox.Name = "pBox";
this.pBox.Size = new System.Drawing.Size(264, 272);
this.pBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pBox.TabIndex = 0;
this.pBox.TabStop = false;
this.pBox.DoubleClick += new System.EventHandler(this.pBox_DoubleClick);
this.pBox.Click += new System.EventHandler(this.pBox_Click);

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(279, 293);
this.Controls.Add(this.pBox);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Click += new System.EventHandler(this.Form1_Click);
((System.ComponentModel.ISupportInitialize)(this.pBox)).EndInit();
this.ResumeLayout(false);

}

Step 5:
Build your code and thus you can run your appilcation.

Wednesday, July 16, 2008

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.

Virtual Directory Configuration

It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level.
This error can be caused by a virtual directory not being configured
as an application in IIS.

This error occurs due to the following two reasons

1) Either there are two web config file, or your web config file is not in the current directory.

2) There must be some syntax error in web.config file

Sample Web Application using ASP.NET 2008

Sample Web Application using ASP.NET 2008

The following content describes the step-by-step procedure to create a new simple website ShopCart in Visual Studio 2008. The connection to the SQL Server database is also explained using ADO.NET

Introduction: The following simple 11 steps help the developer to create a web application, to know basic features of .Net, and learn Connection to the database, who is new to .Net Technology. The web application SHOPCART allows the following features.

1. User can add new items to the database.
2. View the existing items in a grid view.

These features are very simple and basic things for a fresher to learn and know about creating web site in Visual Studio 2008. The Database connection-using ADO.Net is explained and SQL queries to create tables, inserting records and selecting data are explained.

Platform: .Net 2008
Language: C#
Database: SQL Server 2005

Who is it For: This article is useful for a fresh developer who is very new to .Net Technology.

Step 1: Launch Microsoft Visual Studio 2008 from Start Menu -> Programs -> Microsoft Visual Studio 2008 -> Microsoft Visual Studio 2008

Click on File -> New -> Website as shown.



Step 2: The following window appears, select the ASP.NET Web Site (by default this option is selected) template. And select the Language from Language dropdown list, (by default VB.Net is selected). Here I have selected the language as C#. Then, locate your website in any of the location and give any name for your website and click OK button. Here, I have given the website name as ShopCart, please see below.




Step 3: Thus, the Website named ShopCart is loaded, with a page called default.aspx. This is an aspx page, where you can design your web page and code accordingly. Now switch to Design view of the default.aspx page. This is how your Design view of the page looks like:




The Toolbox tab allows you to drag and drop web controls like Textbox, Button, Label, Dropdown List, Grid View, Link Button and many such controls.



Step 5: Now drag Label Control from Toolbox, which appears in the default web page. Right Click on Label and go to Properties. The Properties window appears enter the text WELCOME TO SHOPCART and you can increase font, change its color using Font properties as shown.




Step 6: Drag and drop button controls from Toolbox, and go to their properties, enter text as Add Items, View Items as shown below.



Step 7: Now, lets add one more web page to add items to our website shop cart. To do this, click on Solution Explorer tab, right click on ShopCart and click on Add new Item as shown below.



The following window appears, enter AddItem.aspx as your web page name and click on Add button.



In the similar way, add one more webpage called ViewItem.aspx.


Step 8: Now click on Default.aspx page, and double click on Add Items button, which navigates to Button1_Click event. Write the following code in Button1_Click event.

Response.Redirect("AddItem.aspx");


Similarly double click on View Items button in Default.aspx page, which navigates to Button2_Click event Write the following code in Button2_Click event

Response.Redirect("ViewItem.aspx");

Thus, your page should look like this.





Step 9: Go to Design view of AddItem.aspx page; add 3 labels name Item Name, Description, Item Price and 3 text boxes and 2 buttons named Add and Cancel.
The page should be designed as below




Now double click on Add button, which takes you to Button1_Click event. Write the following code in the Button1_Click event.

string strItemName = TextBox1.Text.ToString();
string strDescription = TextBox2.Text.ToString();
string strPrice = TextBox3.Text.ToString();

//Database connection string
string strConn = "server=SQLSERVERNAME;database=SHOPCART;uid=username;pwd=password;";
string strQuery ="Insert Into ADDItem(Name,Description,Price) Values ('"+strItemName+"', '"+strDescription+"', '"+strPrice+"')";

// using ADO.NET to connect to the database and execute the query
SqlConnection sqlConn = new SqlConnection(strConn);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = strQuery;
sqlConn.Open();
sqlCmd.Connection = sqlConn;
sqlCmd.ExecuteNonQuery();
sqlConn.Close();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Label5.Text = " Data Added Successfully";

And add the following in the namespaces
using System.Data.SqlClient;

Note: For the Database I have used SQL Server, you need to write the SQL Server name, username and password in the strConn variable.
In the SQL Server, create a database named SHOPCART, add new table named ADDItem, with columns such as Name, Description, Price.

Here is the query to create a table in SQL

Create table ADDItem
(
Name varchar(50),
Description Varchar(100),
Price varchar(20)
)


With this, you should able to add Items to database.

Now, lets see how to view the items in a grid view.

Step 10: Go to Design view of ViewItem.aspx page, add a grid view from the Toolbox menu, go to its properties make AutoGenerateColumn false, click on Auto Format and choose any of the formats. And then click on Edit Columns Items, add the BoundField column, enter HeaderText and DataText fields as follows.




Thus, your page should appear as follows




Step 11: Press F7 key in ViewItem.aspx page, which navigates to the page load event of the ViewItem. In the page load event write the following code:

//Database connection string
string strConn = "server=SQLSERVERNAME;database=SHOPCART;uid=USERNAME;pwd=PASSWORD";
string strQuery = "Select * from AddItem";
// using ADO.NET to connect to the database and execute the query
SqlConnection sqlConn = new SqlConnection(strConn);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = strQuery;
sqlConn.Open();
sqlCmd.Connection = sqlConn;
SqlDataReader rdr;
rdr = sqlCmd.ExecuteReader();
sqlConn.Close();
GridView1.DataSource = rdr;
GridView1.DataBind();

And add the following in the namespaces
using System.Data.SqlClient;

Note: You can add back buttons on each page and write Response.Redirect(“Default.aspx”) on button click event, thus helps to navigate on each page.

Now, go to Solution Explorer, right click on Default.aspx and select Set as Start page.
Compile your code using F10 key. The build should be succeeded and you should be able to run your shop cart application. To debug the code, can use F5 key.

Conclusion: Thus, the developer should be able to know, how to create a new web application, how to add new web pages, how to insert data into SQL Database, how to fetch data from SQL to ASP.Net using ADO.NET, how to present to the end customer using grid view control and how to build and run your web application.

Wednesday, June 11, 2008

Validate an email address using Regular expressions.

This sample code snippet helps to validate an email address using regular expressions. Returns true is the address provided is true, otherwise returns false
public bool IsValidEmail(string email)
{
string pat = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.(comeduinfogovintmilnetorgbiznamemuseumcoopaeroprotv[a-zA-Z]{2})$";
Regex check = new Regex(pat,RegexOptions.IgnorePatternWhitespace);
bool valid = false;
if (string.IsNullOrEmpty(email))
{
valid = false;
}
else
{
valid = check.IsMatch(email);
}
return valid;
}

ASP.NET Pass values between pages

  1. use server.transfer()oruse crosss page submission
  2. use querystring:Response.Redirect("secondpage.aspx?value=" +saravanan) in seconpage:string name=request.querystirng["value"];
  3. refer this link:http://aspnet.4guysfromrolla.com/articles/020205-1.aspx