"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, October 30, 2010

Text to speech in asp.net

step 1 : create new web site.
step 2 :  in the default.aspx page, copy the following code…

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>Text to speach</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:TextBox ID="txtspeach" runat="server"></asp:TextBox>
 <br />
 <asp:Button ID="btn1" runat="server" Text="Speach" onclick="btn1_Click" />
 </div>
 </form>
</body>
</html>






Step 3: Right click on the solution explore of the visual studio and add reference
in the add reference dialog box select the COM tag and add “Microsoft Speech Object library” and click to ok.
Step 4 : In the Default.aspx.cs file, copy the following code……
using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpeechLib;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
 protected void btn1_Click(object sender, EventArgs e)
 {
 SpVoice objspeach = new SpVoice();
 objspeach.Speak(txtspeach.Text.Trim(), SpeechVoiceSpeakFlags.SVSFDefault);
 objspeach.WaitUntilDone(Timeout.Infinite);
 }
}

Step 5 : Run the code…
enter the text which u want to speech and then click to button, and listen the text…..





Have a nice day... 'N happy Coding :)

Tuesday, October 12, 2010

Some of Visual Studio’s Shortcuts

Here are some Visual Studio shortcuts that helped me increase my coding speed and also to be smart among other developers.
  • Open Smart Tag: Ctrl + .
  • Cycle Clipboard Ring: Ctrl + Shift + V
  • Go to Definition: F12
  • Go to Line: Ctrl + G
  • Vertical Block Selection: Alt + Mouse or Shift + Alt + Right Arrow
  • View Properties Window: F4 or Alt + Enter
  • Comment Selection: Ctrl + K, Ctrl + C
  • Uncomment Selection: Ctrl + K, Ctrl + U
  • Toggle Code / Design Views: F7
  • Incremental Search: Ctrl + I
  • View Object Browser: Ctrl + Alt + J
  • Delete Line: Ctrl + L or Shift + Delete
  • Add New Item to Project: Ctrl + Shift + A
  • Find All References: Shift + F12
  • The Rename Refactor: Ctrl + R, R
  • Find All References: Shift + F12
  • Format Document: Ctrl + K, Ctrl + D
  • View Task List: Ctrl + \, Ctrl + T
  • Find in Files: Ctrl + Shift + F
  • Toggle Outlining Expansion: Ctrl + M, Ctrl + M
  • Save Any Output Window: Ctrl + S
  • Build Solution: Ctrl + Shift + B
Have a nice day... 'N happy Coding :)

Enable and disable Trigger in SQL Server

Disable Triggers instead of dropping them.
================================

Business rules in table often expect your application to update the table one row at a time. Also some triggers generate error when the code in the trigger assigns to a local variable returned by selecting a column from the inserted virtual table. The assignment fails if you are updating multiple rows because the inserted table contains more than one row so the sub query returns more than a single value. Multiple updates need special handling in such scenario. Developers often wind up dropping a trigger before multi- row updates then creating them later.

But this scenario can be overcome by disabling trigger

Alter Table Mytable Disable Trigger mytrigger

You can enable Trigger using
Alter Table Mytable Enable Trigger mytrigger
Have a nice day... 'N happy Coding :)

Retrieve Query result(records) as Comma Separated Value in SQL Server

Its been a while that i've posted an article here. This time i am sharing a technique by which you can retrieve result from MS SQL Server in the form of Comma Separated Values(CSV). The idea is to display all the states from a particular country in CSV format.For this purpose we first create a table and name it "Country". Then we create two fields in the table, one for holding the country name and the second for holding the state name, say "countryname" and "state" respectively. After Creating the above table copy and paste the below code in your SQL Query Analyzer and Run it. Now you can see the magic!!. What is the idea behind this query?. Lets examine it.

DECLARE @s varchar(3500)

SET @s=''

SELECT @s=state +','+@s FROM Country WHERE countryname='INDIA'

SELECT @S

The keyword DECLARE is used to declare a variable named s and declare its datatype as varchar which can hold upto 3500 chars. Then we use the SET keyword to null string because if we dont assign it to null string the result will also be null. Now we use SELECT keyword to assign the result set into @s. Then at last we print our result using the last SELECT Keyword.

I know what i presented here is not a "Big thing", But every one knows nothing is so simple ever
Have a nice day... 'N happy Coding :)

SQL Server Date Time Formats using Query

We can format the sql server 'datetime' field into a specific date time format. SQL Server provides this functionality through an inbuilt function called CONVERT(). For Example you can get the date format in dd/mm/yy by using the following query.

Select Convert(Varchar(10),GetDate(),3) from your_table_name.

Look at the third integer parameter you are passing(i.e. 3), which does the formating part.

Following are the values and thier corresponding formats :

1----------------- mm/dd/yy
2-----------------yy.mm.dd
3-----------------dd/mm/yy
4-----------------dd.mm.yy
(And so on. Other format numbers range from 100-114, 120,121,126,130,131) .Try it n see the results yourself.....enjoy


Have a nice day... 'N happy Coding :)

run command promt command in asp.net

hi,
As a part of my current project i need to run command promt command in asp app.it's nice i'm sharing the code here


          
  System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo("cmd.exe");

            si.RedirectStandardInput = true;

            si.RedirectStandardOutput = true;

            si.RedirectStandardError = true;

            si.UseShellExecute = false;

            si.CreateNoWindow = true;

            si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            System.Diagnostics.Process console = System.Diagnostics.Process.Start(si);

            console.StandardInput.WriteLine(" *** Your command Comes Here*** ");


Hope it helped u someways



Have a nice day... 'N happy Coding :)

Run application in asp.net c#

you have a button on ASP.NET page, when press this button - one application is invoked.


the code to run application (for example, notepad) is (on C#)

System.Diagnostics.Process.Start("notepad");


On details:

            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName = @"c:\WINDOWS\system32\notepad.exe";

            processStartInfo.Arguments = @"c:\test.txt";

            Process.Start(processStartInfo);


but the problem is that the application doesn't run, i.e. no window is opened.

Note that ASP.NET code is executed on the SERVER.

Solution:

ASPNET user under which application is run should have appropriate security settings.

1. change local policies for APSNET user:
in WinXP: run secpol.msc

go to Local Policies->User Rights Assignment

find "Deny logon locally" and remove ASPNET user from it.
also find "Deny logon .. terminal" and remove ASPNET user from it.



2. Security for files.
if your application needs also to work with files (open, save, etc) you have to change security settings for the folders to allow user ASPNET modify nedeed files.

to do this:
- In Explorer right button mouse click the folder and select "Properties"
- In Security tab, add "ASPNET" in and give desired permissions (Read, Write, Execute, etc).


To test how it works without starting ASP.NET site you can try run in Windows command line:

runas /user:ASPNET "notepad.exe"

it asks you for the password of ASPNET user. enter the password. 
if everything is done correct you will see opened application (notepad in our example) in new window.


I've tried this on my Windows XP Professsional and it worked fine.


Read more

- Unable to Start a Process from ASP.NET
http://support.microsoft.com/kb/555134


- ASP.NET Impersonation
http://msdn.microsoft.com/en-us/library/aa719560.aspx

- How to configure the process identity for the ASPNET account in ASP.NET 1.1 when you use IIS 5 Isolation mode in IIS 6.0 on Windows Server 2003

Have a nice day... 'N happy Coding :)

Saturday, October 9, 2010

gridview row color based on different values


depending up on x and y condition , changing the background color of the row

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // check your condition here
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string strValue = DataBinder.Eval(e.Row.DataItem, "SomeColumn").ToString();
        //do something with the values and set color
        switch (strValue)
        {
            // change row color
            case "Something 1":
                e.Row.BackColor = System.Drawing.Color.Red;
                break;
            case "Something 2":
                e.Row.BackColor = System.Drawing.Color.Yellow;
                break;
            case "Something 3":
                e.Row.BackColor = System.Drawing.Color.Violet;
                break;
            case "Something 4":
                e.Row.BackColor = System.Drawing.Color.Teal;
                break;
        }
    }
}


Have a nice day... 'N happy Coding :)

Friday, October 8, 2010

SQL Server Login Issue With Default Database

Every once in a while you may run into an issue where a user cannot login to SQL Server, because the logins default database may not be available.  This could be for several reason such as that database was dropped, the database may be corrupt, the database is offline, the user no longer has access to the database or even because the database was renamed.  When this happens the user will see an error message like the following on SQL Server 2005 and get a 4064 error.
Or this error message for SQL Server 2008 and get a 18456 error.
Or if you are using a command line tool, you may see a text error like this: "Error: 18456, Severity: 14, State: 40. Login failed for user 'sqldbpool'. Reason: Failed to open the database specified in the login properties. [CLIENT: 10.10.10.10]".
Solution
This issue may not come up that often, but if it does here is a simple fix.  The user can connect to another database, such as the master and then the default database can be changed.
Using SQL Server Management Studio
Step 1: Open SSMS and click on "File" and then "Connect Object Explorer..."



Step 2: Enter the server name, select the authentication mode, in this case I am using SQL Server Authentication where I also need to enter a login and password. Then click on the "Options >>" button 

Step 3: On the "Connection Properties" tab, type a different database name into the "Connect to database" drop down. You should be able to just connect to the master database, since all users have access to that database by default or you enter another database that you know the user has access to.  Here is what this looks like for both SQL Server 2005 and SQL Server 2008.
Step 4: At this point you can work with SQL Server as normal.  If you want to change the default database you can open a query window and execute the below query to change the default database for the login Note: sp_defaultdb will be removed from the future version of SQL Server so you will need to use the ALTER command.  Be careful with the database you select.  You can pick any database you want as the default database, but if the user does not have access to the database they will get the same error.
EXEC sp_defaultdb 'sqldbpool', 'master'
OR
ALTER LOGIN sqldbpool
with DEFAULT_DATABASE = master

Using SQL CMD
You can use SQLCMD or OSQL to login to SQL Server. You can use the –d switch, as shown below, to specify the database name.  In this example I am connecting to the msdb database.  Once you are connected you can do the same as Step 4 above to change the default database.
List Default Database for Logins 
To get a list of all logins and their default databases you can use this query to retrieve the login, its default database and database status information to see whether the database is online or not.
select name, 
       loginname, 
       dbname as DefaultDB, 
       DATABASEPROPERTYEX(dbname, 'Status') as DBStatus
from sys.syslogins
order by DBstatus
Next Steps
  • Develop a script to fix logins with a default database issue
  • Use the query above to list all of your logins and their default databases to see if there are any potential issues
  • Also, make sure you check that the user login has access to a database if you change their default database.
Hope it helped u someways... :)

Have a nice day... 'N happy Coding :)

Thursday, October 7, 2010

splitting a sentence into characters by characters using CharEnumerator

Hi everybody,
last day i faced a need like this. to split all characters in a sentence one by one and i used CharEnumerator for that it helped to do it easily.


Code


    protected void CharEnumerator_Demo()
    {
        string _d = "My name is Arun";
        Response.Write("Input:My name is Arun");
        Response.Write("<br />");
        Response.Write("OutPut:");
        Response.Write("<br />");
        CharEnumerator chs = _d.GetEnumerator();
        while (chs.MoveNext())
        {
            Response.Write(chs.Current);
            Response.Write("<br />");
        }
    }


Output






















Have a nice day... 'N happy Coding :)

Tuesday, October 5, 2010

display wait message on server controlled event and on page load also

Last day one asked a question on http://forums.asp.net/ . He need to show a wait message on page load and same message on some server control rendering like Selectedindexchanged in drop-down and  text-changed in textbox.I liked that question because i had done both but using different type message ( for page load normal div show \hide, server control rendering ajax update progress  ). he need a Unique solution. Later I changed that Div a little bit and find the solution for that.

Here It is. on Html


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">


function hideLoading() {
    document.getElementById('pageIsLoading').style.display = 'none'; // DOM3 (IE5, NS6) only
}
function ShowLoading() {
    document.getElementById('pageIsLoading').style.display = 'Block'; // DOM3 (IE5, NS6) only
}

</script>
</head>
<body>
<body onload="hideLoading()">

    <form id="form1" runat="server">
    <div id="pageIsLoading" runat="server" style="position: absolute; display: block; padding-left: 50px; padding-right: 12px; width: auto; height: 65px; line-height: 40px; border: 1px solid #CCCCCC; color: #000000; font-weight: bold; font-family: verdana; font-size: 12px; background-color: #ffffff; background-image: url(http://localhost:8080/images/bannerz.jpg); background-position: 100px center; background-repeat: no-repeat;">
    <script type="text/javascript">
        var window_width;
        var window_height;
        if (typeof (window.innerWidth) == 'number') {
            window_width = window.innerWidth;
            window_height = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            window_width = document.documentElement.clientWidth;
            window_height = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            window_width = document.body.clientWidth;
            window_height = document.body.clientHeight;
        }
        var left = Math.round((window_width - 240) / 2);
        var top = Math.round(((window_height - 130) / 3) + 30);
        document.getElementById('pageIsLoading').style.left = left + 'px';
        document.getElementById('pageIsLoading').style.top = top + 'px';
    </script><p><p><p><p>
    Loading <strong class="highlight">page</strong>..Please <strong class="highlight">wait</strong>...<img src="images/ajax-loader.gif" alt="" title="Loading..." />
</div>
    <div>
    <asp:TextBox ID="txt" Text="1232" runat="server" AutoPostBack="true" ontextchanged="txt_TextChanged" ></asp:TextBox>
    </div>
    </form>
</body>
</html>


on server side



using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Threading;
using System.Diagnostics;

public partial class loading : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Thread.Sleep(10000);
        }
    }
    protected void txt_TextChanged(object sender, EventArgs e)
    {
        pageIsLoading.Style["Display"] = "Block";
        Thread.Sleep(10000);
    }
}


Hope it help u someways
Have a nice day... 'N happy Coding :)