Sunday, September 18, 2011

"Make your computer to speak what you write in Textbox" application in asp.net

Download Aspnetaudio setup from
www.aspnetaudio.com/aspnetaudio_Download.aspx


Import .dll file into your application


Now start with application


In .aspx page



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<%@ Register assembly="ASPNetAudio.NET3" namespace="ASPNetAudio" tagprefix="ASPNetAudio" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


         <asp:TextBox ID="TextBox1" runat="server" Height="152px" TextMode="MultiLine" 
          
  Width="216px"></asp:TextBox>
  


    <asp:Button ID="Btnplay" runat="server" onclick="Btnplay_Click" Text="speak" />
    
<ASPNetAudio:Audio ID="Audio1" runat="server" 
        AudioURL="YouTube - kalyug - Jiya dhadak dhadak.mp3">
    </ASPNetAudio:Audio>

   <p>
        &nbsp;</p>
    <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="play" />
  


In code behind file

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SpeechLib;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Btnplay_Click(object sender, EventArgs e)
    {
        SpVoice voice = new SpVoice();
        string s=TextBox1.Text;
        voice.Speak(TextBox1.Text, 0);
        voice.Rate = 10;
    }
  
}

Record and Play your voice application in asp.net

Here in this example i will show how to record and play your voice

Take control in .aspx page

 <asp:Button ID="BtnRecord" runat="server" Text="Record" onclick="BtnRecord_Click" />
        <br />
        <asp:Button ID="Btnsavestop" runat="server" Text="SaveStop"
            onclick="Btnsavestop_Click" />
        <br />
        <asp:Button ID="Btnread" runat="server" Text="Read" onclick="Btnread_Click" />

Now in code behind file  .cs


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.VisualBasic.Devices;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;

public partial class _Default : System.Web.UI.Page
{
    [DllImport("winmm.dll",EntryPoint="mciSendStringA")]
    private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

    protected void Page_Load(object sender, EventArgs e)
    {
        Computer computer = new Computer();
         computer.Audio.Play("c:\\Mere Bina.mp3", AudioPlayMode.WaitToComplete);
    }
protected void BtnRecord_Click(object sender, EventArgs e)
{
  
    mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
    mciSendString("record recsound", "", 0, 0);

}
protected void Btnsavestop_Click(object sender, EventArgs e)
{
    mciSendString("save recsound c:\\record.wav", "", 0, 0);
    mciSendString("close recsound ", "", 0, 0);
    Computer c = new Computer();
    c.Audio.Stop();

}
protected void Btnread_Click(object sender, EventArgs e)
{
    Computer computer = new Computer();
    computer.Audio.Play("c:\\record.wav", AudioPlayMode.WaitToComplete);

}
}

to get better result use microphone


Friday, September 16, 2011

Confirmation while deleting record from gridview in asp.net


Here i used LinkButton to show Delete link on gridview
<asp:GridView ID="GridView1" Runat="server" 
    DataSourceID="employeeDataSource" AutoGenerateColumns="False" DataKeyName="empid" >
   
    <Columns>

        <asp:BoundField HeaderText="Last" DataField="LastName" 
           SortExpression="LastName"></asp:BoundField>

        <asp:BoundField HeaderText="First" DataField="FirstName" 
           SortExpression="FirstName"></asp:BoundField>

        <asp:BoundField HeaderText="Hire Date" DataField="HireDate" 
           SortExpression="HireDate"
            DataFormatString="{0:d}">
        </asp:BoundField>

        <asp:TemplateField HeaderText="Seniority">
            <ItemTemplate>
               <asp:LinkButton id="Linkbutton1" runat="server" onClientClick="return confirm('Do you want to delete')" onCommand="Delete">Delete</LinkButton>
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>

    <SelectedRowStyle ForeColor="White" Font-Bold="True" 
         BackColor="#CE5D5A"></SelectedRowStyle>
    <RowStyle BackColor="#F7F7DE"></RowStyle>
</asp:GridView>

<asp:SqlDataSource id="employeeDataSource" runat="server" SelectCommand="select LastName,FirstName,HireDate from employee" DeleteCommand="Delete from employee where empid=@empid">

while deleting any particular record, it will ask for confirmation.
Here i used "onClienClick" property in linkbutton,it will run before getting postback and ask user for confirmation if user click ok "onCommand" get fire by calling DeleteCommand and record get deleted.

Tuesday, September 13, 2011

URL Encode and Decode in asp.net

Using HTML Encode and Decode

string text="This is Encode and Decode program";

To Encode
Server.HtmlEncode(text);

To Decode
Server.HtmlDecode(text);

Using ASP.NET Encode and Decode

To Encode
HttpServerUtility.UrlEncode(text);

To Decode
HttpServerUtility.UrlDecode(text);