Thursday, December 17, 2009

Split String

string str = ds.Tables[0].Rows[0].ItemArray[1].ToString();
string[] str1 = str.Split(new char[] { ',' });
v1 = str1[0].ToString();
v2 = str1[1].ToString();

Tuesday, December 15, 2009

Get the IP address in a Windows application

Using .NET 1.1 and 2.0 to retrieve the IP address
Well, in .NET 1.1 and 2.0 there are methods in the System.Net namespace that do that. Speaking of System.Net, don't forget to include the using statement, to avoid the long lines I have below:

using System.Net;

// Get the hostname
string myHost = System.Net.Dns.GetHostName();
// Show the hostname
MessageBox.Show(myHost);
// Get the IP from the host name
string myIP = System.Net.Dns.GetHostByName(myHost).AddressList[0].ToString();
// Show the IP
MessageBox.Show(myIP);

Friday, December 11, 2009

How to send an Email through Window Application with C#

private void btnSend_Click(object sender, EventArgs e)
{
string sTo = txtToEmailAddress.Text;
string sFrom = txtEmail.Text;
string sSubject = txtSubject.Text;
string sBody = txtBody.Text;

try
{
MailMessage mail = new MailMessage(sFrom, sTo, sSubject, sBody);
SmtpClient client = new SmtpClient("IP address");
client.Send(mail);
MessageBox.Show("Mail Successfully Sent");
txtSubject.Text = "";
txtEmail.Text = "";
txtBody.Text = "";
}
catch (Exception)
{
MessageBox.Show("Mail Sending Fail");
}
}

Saturday, November 28, 2009

Web Application : C# Function for Insert,get data and fill the dropdown list

//To get data from database
public object getdata(string str)
{
string constr;
constr = "ConnectionString";
SqlConnection con = new SqlConnection(constr);
con.Open();
object a;
SqlCommand cmd = new SqlCommand(str,con);
a = cmd.ExecuteScalar();
con.Close();
return a;
}
//To inserting data into the database
public void insertdata(string str)
{
string constr;
constr = "ConnectionString";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand(str,con);
cmd.ExecuteNonQuery();
con.Close();
}
//To fill the dropdownlist
public void dataset(DropDownList ddl,string str)
{
string constr;
constr = "ConnectionString";
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter dap = new SqlDataAdapter(str, con);
con.Open();
DataSet ds = new DataSet();
dap.Fill(ds);
ddl.Items.Add("Select Option");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if(!string.IsNullOrEmpty(ds.Tables[0].Rows[i].ItemArray[0].ToString()))
{
ddl.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
con.Close();
}

Tuesday, November 24, 2009

free sms webservice to send sms using way2sms

http://www.aswinanand.com/sendsms.php(WEBSERVICE)
Now go through this link : http://www.aswinanand.com/2008/07/send-free-sms-web-service/

By the above web service link any one can able to send free sms through ASP.Net code via way2sms.
Implementation of webservice in our code:
Before using you should create way2sms account to use this webservice.

Method to add webreference in visual studio:

1.Right click ur project and click AddWebReference and paste the above top link in it then it will produce xml code below and click ok.
then follow/use the below code

you can write below code in Button event for trial purpose..
com.aswinanand.www.SendSMS sms = new com.aswinanand.www.SendSMS();
sms.sendSMSToMany("ur way2sms username","password","to number","message");

Please go with this url :
http://way2sms.codeplex.com/

Thursday, September 3, 2009

.NET Remoting

Interview Questions
.NET Remoting


1. What’s a Windows process?
It’s an application that’s running and had been allocated memory.

2. What’s typical about a Windows process in regards to memory allocation?
Each process is allocated its own block of available RAM space, no process can access another process’ code or data. If the process crashes, it dies alone without taking the entire OS or a bunch of other applications down.

3. Why do you call it a process? What’s different between process and application in .NET, not common computer usage, terminology?
A process is an instance of a running application. An application is an executable on the hard drive or network. There can be numerous processes launched of the same application (5 copies of Word running), but 1 process can run just 1 application.

4. What distributed process frameworks outside .NET do you know?
Distributed Computing Environment/Remote Procedure Calls (DEC/RPC), Microsoft Distributed Component Object Model (DCOM), Common Object Request Broker Architecture (CORBA), and Java Remote Method Invocation (RMI).

5. What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services.

6. When would you use .NET Remoting and when Web services?
Use remoting for more efficient exchange of information when you control both ends of the application. Use Web services for open-protocol-based information exchange when you are just a client or a server with the other end belonging to someone else.

7. What’s a proxy of the server object in .NET Remoting?
It’s a fake copy of the server object that resides on the client side and behaves as if it was the server. It handles the communication between real server object and the client object. This process is also known as marshaling.

8. What are remotable objects in .NET Remoting?
Remotable objects are the objects that can be marshaled across the application domains. You can marshal by value, where a deep copy of the object is created and then passed to the receiver. You can also marshal by reference, where just a reference to an existing object is passed.

9. What are channels in .NET Remoting?
Channels represent the objects that transfer the other serialized objects from one application domain to another and from one computer to another, as well as one process to another on the same box. A channel must exist before an object can be transferred.

10. What security measures exist for .NET Remoting in System.Runtime.Remoting?

None. Security should be taken care of at the application level. Cryptography and other security techniques can be applied at application or server level.

11. What is a formatter?
A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end.

12. Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperable.

13. What’s SingleCall activation mode used for?
f the server object is instantiated for responding to just one single request, the request should be made in SingleCall mode.

14. What’s Singleton activation mode?
A single object is instantiated regardless of the number of clients accessing it. Lifetime of this object is determined by lifetime lease.

15. How do you define the lease of the object?
By implementing ILease interface when writing the class code.

16. Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config.

17. How can you automatically generate interface for the remotable object in .NET with Microsoft tools?
Use the Soapsuds tool.

Tuesday, May 12, 2009

DOT NET Interview Questions

(According to latest VS.NET 2005 whidbey)
(Including SQL ServerUML,Architecture,Project
Management and General Interview Questions)
http://rapidshare.com/files/61630032/DotnetInterview.pdf

Tuesday, April 14, 2009

How to go back to the previous page in ASP.NET 2.0 with C#

// static variable
static string prevPage = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
prevPage = Request.UrlReferrer.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect(prevPage);
}
--------------------
protected void Page_Load(object sender, EventArgs e)
{
if( !IsPostBack )
{
ViewState["RefUrl"] = Request.UrlReferrer.ToString();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
object refUrl = ViewState["RefUrl"];
if (refUrl != null)
Response.Redirect((string)refUrl);
}



Wednesday, April 8, 2009

Paging With SQL Server Stored Procedures In ASP.NET

Data paging is very useful when you work with large amount of data. Instead of confusing your user with thousands or maybe even millions of records you simply show only first page with 10, 20 or 30 records and enable navigation buttons like Next or Previous if user wants to see other pages. Standard ASP.NET server controls, like GridView have built in paging capabilities in two modes: simple or custom.

Simple paging is easy to implement but it always bind complete records set which is not so scalable solution and can take a lot of network traffic and work very slow if you have large table or your web site is on shared hosting or especially if you have a lot of concurrent visitors. More about how to implement simple or custom paging in GridView and ListView you can read in Data Paging in ASP.NET tutorial.

But, which ever server control you use for data presentation, to get efficient and scalable data paging you need to do all your paging logic on SQL Server's side and SQL Server should return only selected page to ASP.NET web application. With logic like this, you get faster solution, need less memory and avoid too much traffic between SQL Server and web server. On SQL Server side, you can do paging on two main ways:

1. By building a dynamic SQL query

2. By using a stored procedure

Both methods are used widely, to find out how to build dynamic SQL queries for paging check SQL Queries For Paging In ASP.NET. In this tutorial we will see some common solution when paging is done with stored procedure.


Paging stored procedure with three nested queries

I will publish next time.

Setting the maximum length of a singleline/multiline text box

How can I set the maximum length of a singleline/multiline textbox in a webform?

Restricting the length of text on a Single line/Multi line textbox is not supported by the standard ASP.NET Web control. This can be done by adding the following Javascript function in your ASPX page.

1. Add a javascript:
At the top of your ASPX page you will see the following tag . Add the following code under this tag:

function Count(text,long)
{
var maxlength = new Number(long); // Change number to your max length.
if (text.value.length > maxlength){
text.value = text.value.substring(0,maxlength);
alert(" Only " + long + " characters");
}
}

2. Change your text controls on your ASPX page
On every multi-line text box where you would like to control the length, add the following code to the asp text box control.
onKeyUp="Count(this,300)" onChange="Count(this,300)"

Your original text control before adding this code:
<asp:TextBox ID="TESTDATA" runat="server" TextMode="MultiLine">asp:TextBox>

After adding the code:
<asp:TextBox ID="TextBox1" runat="server" onKeyUp="Count(this,300)" onChange="Count(this,300)" TextMode="MultiLine">asp:TextBox>

Saturday, April 4, 2009

Regular Expressions,.NET, C# Programming

Positive decimal value regular expression with max 3 decimal places:
Regular Expressions, .NET, C# Programming Language
* Accepts all positive decimal values (currently only accepts values greater and equal to one (1))
* i.e accepts ---> 0.0001
* Can have maximum 3 decimal places.
* Decimal places are optional.
This regular expression will be used to validate currency input.
1:ValidationExpression="^\d*[1-9]\d*(\.\d+)?$"

Validate Indian Vehicle Number:
@"^[a-zA-Z]{2}[a-zA-Z0-9]{0,6}[0-9]{3}$"

http://www.cs.princeton.edu/introcs/72regular/

Friday, February 6, 2009