Monday, 25 November 2013

Get IP address and Host Name of Local Computer

In the Blog of MSDN i found and article to get host and IP address of computer I wrote a code to get it and it gives both address of IPV6 and IPV4 and we know that there is an array of type IPAddress  . and with the help of foreach it will give all address of computer and if you have virtual machine installed then it will also give IP address of this also.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Networking
{
    class Program
    {
        static void Main(string[] args)
        {

            Program.gethostname();
        }
        public static void gethostname()
        {
            string hostname = Dns.GetHostName();
           
            IPAddress [] ipaddress = Dns.GetHostAddresses(hostname);
            foreach (IPAddress x in ipaddress)
            {
                Console.Write("this is computer name:" + hostname + "and IP address is: " + x);
                Console.ReadLine();
            }
            Console.ReadLine();
        }
    }
}

IF you pass null string in  GetHostAddresses() method it will return same result as it is when pass hostname string in it. look at the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Networking
{
    class Program
    {
        static void Main(string[] args)
        {

            Program.gethostname();
        }
        public static void gethostname()
        {
            string hostname = Dns.GetHostName();
            string k = "";
            IPAddress [] ipaddress = Dns.GetHostAddresses(k);
            foreach (IPAddress x in ipaddress)
            {
                Console.Write("this is computer name:" + hostname + "and Ipa address is: " + x);
                Console.ReadLine();
            }
            Console.ReadLine();
        }
    }
}

Wednesday, 20 November 2013

Send Email Through GoDaddy Server to other Email Account in Asp.net

Suppose in your website you have a contact us or career page in which user may send his data or can contact you and you want that data on y our Gmail, Outlook, Hotmail or other email account. First of all look at the form
In the above form if you want to receive user data on you different email accounts then one thing you should consider in your mind.

 Web browser is not going to directly send data in your email account (email will be send through other email account) , So you will have to give an interface through which your server can send data from client side.

So how you will do it in Asp.net ? for this you will have to go through following steps.

1. add name space
                         using System.Net;
                         using System.Net.Mail;
2. On click event of submit button write following code.
 1. Create an object of MailMessage class like this

         MailMessage msg = new MailMessage(); 
in this object you will get many properties and method to use in sending email

            string email = "Write Here The email ID on which you want to Receive Data";
            string name = "Email ID";
// Now mainmessage string will contain data in prescribe format in which you want
            string mainmessage = "<html><body>Name : " + TextBox1.Text + "<br />" + "Email ID: : " +     TextBox2.Text + "<br />" + "Contact No : " + TextBox3.Text + "<br />" + "Website Name : " + TextBox4.Text + "<br />" +
                "Message : " + TextBox5.Text + "<br /></body></html>";
            MailMessage msg = new MailMessage();
            msg.Subject = "Message or Feedback From a User";
            msg.Body = mainmessage;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            msg.From = new MailAddress(TextBox2.Text);
            msg.To.Add(new MailAddress(email.Trim(), name));
            SmtpClient smptc = new SmtpClient(); // Here SMTP Client object is created
            smptc.Host = "smtpout.asia.secureserver.net";// here SMTP interface Address is passed
            smptc.Port = 25;// Use port No 25
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = false;
            smptc.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential credentials = new NetworkCredential("Write Email or User name of GoDaddy Email Account", "Password here");
            smptc.Credentials = credentials;
            smptc.Send(msg);
            Response.Write("<script type='text/javascript'>alert('Thanks! for your feedback.')</script>");
            TextBox1.Text = "";
            TextBox2.Text = "";

Hope this would help you.

Similarly you can use Gmail and Hotmail but due to some security reason they do not like such activity.

Saturday, 16 November 2013

Online Text Editor in Javascript

here I have pic of my simply created online text editor, actually I was working on a project and it needs a form that also can edit text like making it Bold, Italic, underline and many things.
So, In this smallest project I took Text area HTML DOM and few buttons as it is obvious in the above pic.
When person on client side starts writing then simply he or she may need to decorate his or her writing since in database as we know that it will simply store like ordinary data and when we retrieve it it simply display it in string format. To make it decor able after saving we will have to add html tags like </br> to break line and <b></b> to make text bold.

java script function code 

function editor(domofhtml) {


            var Field = document.getElementById('TextArea1');
            var val = Field.value;
            var selected_txt = val.substring(Field.selectionStart, Field.selectionEnd);
            var before_txt = val.substring(0, Field.selectionStart);
            var after_txt = val.substring(Field.selectionEnd, val.length);
            Field.value = before_txt + '<'+ domofhtml +'>' + selected_txt + '</'+ domofhtml +'>' + after_txt;
       
        }
to know about list of in build function and object of java script click on this link and you would be better able to know how they are working in the above function.

here 'TextArea1' is ID of text area box in the above pic. Field store the reference of this and Val it's value and we will have to find start index of selected text and end index of this text so that we can apply our HTML tags 'domofhtml ' is parameter so that we can pass different HTML DOM through same function of click of various type buttons to edit text in TextArea.

Now on the Bold button at onclick event add this function like this

<input id="Button1" type="button" value="Bold" onclick="editor('b');" />

To make Italic text do this on italic button 

<input id="Button2" type="button"  value="Italic" onclick="editor('i');" />
 
and similarly you can add many Tags.

Thank you for giving time, Have a nice day..

Wednesday, 6 November 2013

A Route Named 'something' Could Not Be Found in The Route Collection

This type of problem is really painful while writing code for URL Rewriting, I searched a lot on internet but could not found proper solution so i relinquished this idea but one day I was trying to rewrite URL again and suddenly got the solution for this problem.
you should not worry some much about this simply upload global.asax file in root directory and this will solve your all such problem.
thank you for reading this.