Find  total number of vowels in a string in JavaScript:

                                                     This article explain how to find Vowels in a String and how to find total number of vowels in a string in JavaScript. I have written simple script for checking vowels in a string in JavaScript. I have used regular expression.





<html>
<head>

    <script>
function findVowels() {

var str=document.getElementById('name').value;  

   var vowelC = 0;
var total_findVowels="";
     for (var i = 0; i < str.length; i++) {

     if (str.charAt(i).match(/[a-zA-Z]/) != null) {

        // findVowels

        if (str.charAt(i).match(/[aeiouAEIOU]/))
  {

 total_findVowels=total_findVowels+str.charAt(i);            
 vowelC++;

        }

     }
   }
    document.getElementById('findVowels').value=total_findVowels;
 document.getElementById('findVowels_count').value=vowelC;
   alert("Total Number of findVowels: " + vowelC);
 

}
    </script>

</head>
<body>
<div style="background-color: skyblue; padding:20px">
    <table border="0" cellpadding=3" cellspacing="3">
        <tr>
            <td>
                Enter Input :
            </td>
            <td>
                <input type='text' value='' id='name' name='name'>
            </td>
        </tr>
        <tr>
            <td>
                Vowels Count :
            </td>
            <td>
                <input type='text' readonly="true" value='' id='findVowels_count' name='findVowels_count'>
            </td>
        </tr>
        <tr>
            <td>
                Vowels :
            </td>
            <td>
                <input type='text' readonly="true" value='' id='findVowels' name='findVowels'>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type='button' value='Check' onclick="javascript:findVowels();">
            </td>
        </tr>
    </table>
    </div>
</body>
</html>
               
Read more ...

c# - how to delete all files and folders in a directory?:
This examples shows how to delete all files (*.*) from a folder in C#.
First, you need to get the list of file names from the specified directory (using static method Directory.Get­Files. Then delete all files from the list.
Delete all files
C# code
using System.IO;
string[] filePaths = Directory.GetFiles(@"d:\Images\");
foreach (string filePath in filePaths)
  File.Delete(filePath);

Delete all files (one-row example)
To delete all files using one code line, you can use Array.ForEach with combination of anonymous method.
C# code


Array.ForEach(Directory.GetFiles(@"d:\Images\"),
              delegate(string path) { File.Delete(path); });
Share this post, if it is useful to you. Thanks!.
Read more ...

Get files from directory using CSharp

Posted by Prince | 2:16:00 AM | , | 0 comments »

C# Get All Files from a Folder:
                                                This post shows how to get list of file names from a directory (including subdirectories). You can filter the list by specific extension.
To get file names from the specified directory, use static method Directory.Get­Files. Lets have these files and subfolders in "d:\YourDir" folder:

Get files from directory
Method Directory.GetFiles returns string array with files names (full paths).

C# Code
using System.IO;
string[] filePaths = Directory.GetFiles(@"d:\Images\");
// returns:
// "d:\Images\dotnetcluster.png"
// "d:\Images\home.jpg"


Get files from directory (with specified extension)
You can specify search pattern. You can use wildcard specifiers in the search pattern, e.g. „*.png“ to select files with the extension or „a*“ to select files beginning with letter, a“.

C# Code
string[] filePaths = Directory.GetFiles(@"d:\Images\", "*.png");
// returns:
// "c:\Images\dotnetcluster.png"

Get files from directory (including all subdirectories)
If you want to search also in subfolders use parameter Search Option. A­ll Directories.

C# Code
string[] filePaths = Directory.GetFiles(@"d:\Images\", "*.png",
                                         SearchOption.AllDirectories);
// returns:
// "d:\Images\dotnetcluster.png"
// "d:\Images\Posts\header.png"

Share this post if it is useful to you. Thanks!.
Read more ...

sending mail with attachment in asp.net,c#:
                                                                         In this tutorial you will learn how to send attachment with email in asp.net using c#. To send an email with attachments, the ASP.NET process (or the ASP.NET impersonated account) will need permission to read the file, and attach it to the MailMessage class. You can attach a  file using FileUpload Control and put the file in memory stream. In this example I'm using smtp.gmail.com as my SMTP server.  You can put your gmail login credentials and send mail with attachment.

In .aspx file

 <table style="padding-left: 10px; background-color: #4B8DF8; color: #fff; font-weight: bold;">
        <tr>
            <td colspan="2">
                <span class="primary"><b>Mail With Attachment:</b></span>
            </td>
        </tr>
        <tr>
            <td style="width: 30%">
                From :
            </td>
            <td>
                <asp:TextBox ID="txtFrom" SkinID="textbox_larger" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                To :
            </td>
            <td>
                <asp:TextBox ID="txtTo" SkinID="textbox_larger" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Subject :
            </td>
            <td>
                <asp:TextBox ID="txtSubject" SkinID="textbox_larger" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Message :
            </td>
            <td>
                <asp:TextBox ID="txtMessage" TextMode="MultiLine" SkinID="textbox_multiline_smaller"
                    runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Attach :
            </td>
            <td>
                <asp:FileUpload ID="FileUpload1" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td align="left">
                <asp:Button ID="btnSendMail" runat="server" SkinID="button_primary" OnClick="btnSendMailWithAttachment_Click"
                    Text="Send Mail"></asp:Button>
            </td>
        </tr>
    </table>

Sample screen:
                                     
In .aspx.cs file 

using System;
using System.Data;
using System.Configuration;
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 System.Linq;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSendMailWithAttachment_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(txtTo.Text);
        mail.From = new MailAddress(txtFrom.Text);
        mail.Subject = txtSubject.Text;
        mail.Body = txtMessage.Text;
        mail.IsBodyHtml = true;

        //Attach file using FileUpload Control and put the file in memory stream
        if (FileUpload1.HasFile)
        {
            mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
        }
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential
             ("Your gmail id", "your gmail password");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);

    }
       
}

Please share this post if it's useful to you. Thanks!. 
Read more ...

IEnumerable doesn't have Count:


To resolve this server side error you just add the following namespaces,

 using System.Linq;
 
at the top of your source and make sure you've got a reference to the System.Core assembly.

Read more ...

Upper and Lowercase Conversion - JavaScript:
                                                                Converting a text string to uppercase is very easy using the JavaScript toUpperCase() method and in the same way the toLowerCase() method is used to converting a text string to lowercase. The following code and example shows how this works:
Example:


                             
               
Code:

<html>
<head>
<title>Convert String</title>
<script type="text/javascript" language="javascript">
function changeCase(){
    var txt = document.getElementById("txtChangeText").value;
    var str = new String(txt);
    var changeTo = str.toUpperCase();
    document.getElementById("spnChangedCase").innerHTML = changeTo;
    // var changeTo = str.toLowerCase();//Remove the comment line to convert lowercase
    //document.getElementById("spnChangedCase").innerHTML = changeTo;
}
</script>
</head>
<body>
<div style="background-color: #A5C6FE; padding: 20px">
Type to change UPPERCASE:<input id="txtChangeText" type="text" size="20" onkeypress="changeCase();" />
<span style="color: Red; font-weight: bold" id="spnChangedCase"></span>
</div>
</body>
</html>
Try the demo:

Type to change UPPERCASE:

Read more ...

c# - Enabling And Disabling Buttons In GridView:
In this article  a GridView that has a number of buttons that you need to enable or disable all at once and don't want to have to force a post back on your users in order to loop through them all. By using only a simple js function.

When a GridView renders on the page, it is simply an HTML table and you can traverse it just like you would any other HTML table using JavaScript.

The following code to do a basic version of this in order to enable or disable all buttons in a GridView. First the code gets an instance of the GridView using the ClientID of the GridView, then create a collection of all input controls in the GridView. Next it loops through each input control and checks the type (this is necessary because input controls include not only submit buttons but also things like textboxes). Finally we either enable or disable the submit button.

Code:

<script type="text/javascript" language="javascript">
function disableButtons() 
{
    var gridViewID = "<%=gvReporter.ClientID %>";
    var gridView = document.getElementById(gridViewID);
    var gridViewControls = gridView.getElementsByTagName("input");

    for (i = 0; i < gridViewControls.length; i++) 
    {
        // if this input type is button, disable
        if (gridViewControls[i].type == "submit") 
        {
            gridViewControls[i].disabled = true;
        }
    }
}

function enableButtons() {
    var gridViewID = "<%=gvReporter.ClientID %>";
    var gridView = document.getElementById(gridViewID);
    var gridViewControls = gridView.getElementsByTagName("input");

    for (i = 0; i < gridViewControls.length; i++) {
        // if this input type is button, disable
        if (gridViewControls[i].type == "submit") 
        {
            gridViewControls[i].disabled = false;
        }
    }
}
</script>
Read more ...

Related Posts Plugin for WordPress, Blogger...