Thursday, April 30, 2009

Listview Asp.net 3.5

ASP.NET version 3.5 added two new data Web controls to the Toolbox: the ListView and DataPager. As discussed in the first installment of this article series, Displaying Data with the ListView, the ListView control offers the same built-in features found in the GridView, but much finer control over the rendered output. The ListView's output is defined using a variety of templates, and we looked at examples using the control's LayoutTemplate and ItemTemplates. In particular, these examples used a LayoutTemplate that included a placeholder for the ItemTemplate's rendered output.

The ItemTemplate is rendered for each record bound to the ListView control, and is typically referenced in the LayoutTemplate. This approach generates the rendered markup defined in the LayoutTemplate, plus the rendered markup created by the ItemTemplate for each record. This works fine for simple rendering scenarios, but in more complex scenarios we may need to render different formatting markup for different groups of records. For example, imagine that we needed to display a set of records in a three-column HTML <table>. For each record we would want to emit a table cell (<td>), but for every three records we would need to emit a new table row (<tr>). Such customizations can be accomplished declaratively with the ListView control's includes GroupTemplate and GroupItemCount properties.

http://www.4guysfromrolla.com/articles/010208-1.aspx#postadlink

Wednesday, April 29, 2009

Condition in XPath & Eval C# asp.net for Gridview or Datalist

Here I have if else if else 2 conditions
<%
#XPath("price").ToString() != "" ? "Sales Price:"+XPath("price").ToString() : XPath("listprice").ToString() != "" ? "List Price"+XPath("listprice").ToString() : "Too Low"%>
1 condition:
<%#XPath("detailurl") != "0" ? XPath("detailurl") : "sss"%>
 

Monday, April 27, 2009

Get Country Name Based on User Location For Redirect , Asp.net, C#

Get Country Name Based on User Location For Redirect , Asp.net, C#
 
 
using
System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Globalization;

public

partial class Default3 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Response.Write(

RegionInfo.CurrentRegion.DisplayName);

}

}


http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo(vs.71).aspx

Thursday, April 23, 2009

How to use If condition in XPath C# asp.net 2.0

<%# abc=="" ? XPath("detailurl").ToString() : xyz %>
 
 

Wednesday, April 22, 2009

Browse child node of Amazon Parend Nodes using amazon webservice , asp.net 2.0, C# etc.


Browse child node of Amazon Parend Nodes using amazon webservice , asp.net 2.0, C# etc.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;


public partial class Default2 : System.Web.UI.Page
{
    string strname;
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();

        if (Request["nodeid"] == null)
        {
            doc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YouraccessID&Operation=BrowseNodeLookup&BrowseNodeId=3375251&ResponseGroup=BrowseNodeInfo");
        }
        else
        {
            doc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YouraccessID&Operation=BrowseNodeLookup&BrowseNodeId=" + Request["nodeid"] + "&ResponseGroup=BrowseNodeInfo");
       
        }
       
        XmlNodeList lstIsValid = doc.GetElementsByTagName("IsValid");
        if (lstIsValid.Count > 0 && lstIsValid[0].InnerXml == "True")
        {
            XmlNodeList lstItems = doc.GetElementsByTagName("Children");
            if (lstItems.Count > 0)
            {
               
                XmlNode nItem = lstItems[0];
                foreach (XmlNode nChild in nItem.ChildNodes)
                {
                
                    if (nChild.Name == "BrowseNode") //string compare !
                    {
          
                        strname = strname + "<a  href=Default2.aspx?nodeid=" + nChild["BrowseNodeId"].InnerText + ">" + nChild["Name"].InnerText + "</a><br/>";
                       
                    }
                   
                }
                Response.Write(strname);
       
            }
        }
    }
}

Tuesday, April 21, 2009

Get URL value in code behind C# asp.net 2.0 ServerVariables with parameters

Get URL value in code behind C# asp.net 2.0 ServerVariables with parameters


Request.ServerVariables["SCRIPT_NAME"] /visli/Default.aspx
System.IO.Path.GetFileName(Request.AppRelativeCurrentExecutionFilePath) Default.aspx
System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]) Default.aspx
System.IO.Path.GetFileName(Request.Url.ToString()) Default.aspx
Request.AppRelativeCurrentExecutionFilePath ~/Default.aspx

Monday, April 20, 2009

Captcha Image Submit/Contact/Email Form validation

asp.net 2.0 create and use Captcha image using webservice C# and send email, or contact form :-

1. Create a webservice:- Captcha.ashx

<%@ WebHandler Language="C#" Class="Captcha" %>
using System;
using System.Web;
using System.Drawing;
using System.IO;
using System.Web.SessionState;

public class Captcha : IHttpHandler, IReadOnlySessionState
{
    public void ProcessRequest (HttpContext context) {
        Bitmap bmpOut = new Bitmap(45, 15);
        Graphics g = Graphics.FromImage(bmpOut);
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.FillRectangle(Brushes.Black, 0, 0, 45, 20);
        g.DrawString(context.Session["Captcha"].ToString(), new Font("Verdana", 10), new SolidBrush(Color.White), 0, 0);
        MemoryStream ms = new MemoryStream();
        bmpOut.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        byte[] bmpBytes = ms.GetBuffer();
        bmpOut.Dispose();
        ms.Close();
        context.Response.BinaryWrite(bmpBytes);
        context.Response.End();
    }
    public bool IsReusable {

        get {

            return false;
        }
    }
}


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frndshr.aspx.cs" Inherits="frndshr" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="text-align: center">
            <table style="width: 70%">
                <tr>
                    <td align="right">
                    </td>
                    <td align="left">
                        &nbsp;</td>
                    <td align="left" style="width: 110px">
                    </td>
                    <td align="left" style="width: 373px">
                    </td>
                </tr>
                <tr>
                    <td align="right" style="height: 28px">
                        <asp:Label ID="Label3" runat="server" Text="Your Name:"></asp:Label></td>
                    <td align="left" style="height: 28px">
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
                    <td align="right" style="height: 28px; width: 110px;">
                        <asp:Label ID="Label1" runat="server" Text="Your Email:"></asp:Label></td>
                    <td  align="left" style="width: 373px; height: 28px">
                        <asp:TextBox ID="TextBox1" runat="server" Width="263px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="Label4" runat="server" Text="Friend's Name:" Width="100px"></asp:Label></td>
                    <td align="left">
                        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
                    <td align="right" style="width: 110px">
                        <asp:Label ID="Label2" runat="server" Text="Friend's Email:" Width="94px"></asp:Label></td>
                    <td  align="left" style="width: 373px">
                        <asp:TextBox ID="TextBox2" runat="server" Width="263px"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td style="height: 26px">
                    </td>
                    <td align="right" style="height: 26px" valign="top">
                      <asp:Image ID="imCaptcha" ImageUrl="Captcha.ashx" runat="server" /></td>
                    <td align="left" style="height: 26px; width: 110px;" valign="top">
                    <asp:TextBox ID="txtVerify" runat="server" Width="80px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtVerify"></asp:RequiredFieldValidator>
                    </td>
                    <td style="height: 26px; width: 373px;" align="left">
                        <asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" />
                        <asp:Label ID="labmsg" runat="server" Width="158px"></asp:Label>
                        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CausesValidation="False">Go Back</asp:LinkButton>
                          <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="txtVerify"
            ErrorMessage="Wrong Verification Code.Please Re-enter." OnServerValidate="CAPTCHAValidate"></asp:CustomValidator></td>
                </tr>
                <tr>
                    <td style="height: 26px">
                    </td>
                    <td align="right" style="height: 26px" valign="top">
                    </td>
                    <td align="left" style="width: 110px; height: 26px" valign="top">
                    </td>
                    <td align="left" style="width: 373px; height: 26px">
                    </td>
                </tr>
            </table>
        </div>
    
    </div>
    </form>
</body>
</html>

code behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;


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

        if (!IsPostBack)
        {
            VerificationTxt();
        }
    }

    public void VerificationTxt()
    {
        Random ran = new Random();
        int no = ran.Next(1000, 2000);
        Session["Captcha"] = no.ToString();
    }

    protected void CAPTCHAValidate(object source, ServerValidateEventArgs args)
    {
        if (Session["Captcha"] != null)
        {
            if (txtVerify.Text != Session["Captcha"].ToString())
            {
                VerificationTxt();
                args.IsValid = false;
                return;
            }
        }
        else
        {
            VerificationTxt();
            args.IsValid = false;
            return;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        sndmail();
        VerificationTxt();

    }
    

    void sndmail()
    {
        MailMessage oMessage = new MailMessage();
        oMessage.To = TextBox2.Text;            
        oMessage.From = TextBox1.Text ;         
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //sb.Append(yrnamtxt.Text);
        //sb.Append(" Email ");
       // sb.Append("I found this from abc site , great deals");
        //sb.Append("Subject ");
        //sb.Append("Deal Found");
        oMessage.Subject = "Great Finds";
        oMessage.Body = "I found this from abc site , great deals";
        //oMessage.Attachments = txtBody.Text;

        oMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "webmaster@Domain.com";
        oMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "zzzzzzzz";
        System.Web.Mail.SmtpMail.SmtpServer = "mail.visli.com";

        try
        {
            oMessage = oMessage;
            System.Web.Mail.SmtpMail.Send(oMessage);
            labmsg.Text = "Message Send";
            
           
        }
        catch (Exception Ex)
        {
            labmsg.Text = ("Unable to send mail! " + Ex.Message);
        }


    }




    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx");
    }
}

RequiredFieldValidator and cancel button, Go back button asp.net 2.0 C#

RequiredFieldValidator and cancel button, Go back button asp.net 2.0 C#
 
to put cancel button or response.redirect you have to put like following, so that on click it will not validate form.
 
CausesValidation="False"
<asp:Button id="Button2" runat="server" Text="Cancel"
CausesValidation="False"></asp:Button></P>

 


Rediscover Hotmail®: Get e-mail storage that grows with you. Check it out.

Friday, April 17, 2009

amazom webservice get node name and node id ASP.NET c# , aws

string strname;
protected void Page_Load(object sender, EventArgs e)

{

XmlDocument doc = new XmlDocument();

doc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=xxxxxx&Operation=BrowseNodeLookup&BrowseNodeId=374273011&ResponseGroup=BrowseNodeInfo");

XmlNodeList lstIsValid = doc.GetElementsByTagName("IsValid");

if (lstIsValid.Count > 0 && lstIsValid[0].InnerXml == "True")

{

XmlNodeList lstItems = doc.GetElementsByTagName("Children");

if (lstItems.Count > 0)

{

XmlNode nItem = lstItems[0];

foreach (XmlNode nChild in nItem.ChildNodes)

{

if (nChild.Name == "BrowseNode") //string compare !

{

// Response.Write(nChild["Name"].InnerText + "<br>");

// Response.Write(nChild["BrowseNodeId"].InnerText + "<br>");

//strname=strname+"<a href="+nChild["BrowseNodeId"].InnerText+"><"+ nChild["Name"].InnerText + "</a><br>";

strname = strname +

"<a href=" + nChild["BrowseNodeId"].InnerText + ">" + nChild["Name"].InnerText + "</a><br/>";

}

}

Response.Write(strname);

//Label1.Text = strname;

}

}

}

}


XML get child node 's description C# asp.net

foreach (XmlNode nChild in nItem.ChildNodes)

{

if (nChild.Name == "BrowseNode") //string compare !

{

Response.Write(nChild[

"Name"].InnerText + "<br>");

Response.Write(nChild[

"BrowseNodeId"].InnerText + "<br>");

}

}

Thursday, April 16, 2009

listbox multiple select Sample C# asp.net 2.0

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

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

<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="IdListBox" runat="server" AutoPostBack="true"    SelectionMode="Multiple">
        <asp:ListItem></asp:ListItem>
        <asp:ListItem Value="SO">Settle</asp:ListItem>
        <asp:ListItem Value="SR">Retail</asp:ListItem>
         <asp:ListItem Value="SA">Home</asp:ListItem>
        </asp:ListBox>
        </div>
    </form>
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

Code Behind

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (int i in IdListBox.GetSelectedIndices())
        {
            Response.Write(IdListBox.Items[i].Text);
            Response.Write(IdListBox.Items[i].Value);
        }
    }
    
}


Wednesday, April 15, 2009

Random No generation C#

Random No generation C# between 1 to 600

int RandomNu = RandomNumber(1, 600);

Count Record in access database C# asp.net

string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=c:\\sites\\abcDB.mdb";
     
        string Strsql1 = "select count(Itmno) from svprodtab where Itmno='" + ItemnoCnt + "'";
        
        OleDbConnection MyConnCount = new OleDbConnection(connectionString);
        OleDbCommand cmd1 = new OleDbCommand(Strsql1, MyConnCount);
        MyConnCount.Open();
        int itmcnt = cmd1.ExecuteNonQuery();
        Response.Write("count>" + itmcnt);
        MyConnCount.Close();
        

Gridview ColumnSpan & RowSpan code behind C# asp.net 3.5,2.0

Gridview Column Span & Row Span code behind C# asp.net 3.5,2.0
  
in Row Data Bound

e.Row.Cells[2].ColumnSpan = 2;
e.Row.Cells[2].RowSpan = 2;

CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)


Linq technology is introduced in .Net 3.0 and above.
If you need use namespace of System.XML.Linq, you need reference the following assembly:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll
If you need use namespace of System.Linq, you need to reference this assembly:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll
So, not System.XML.dll you are referring.
And Assembly Reference is not involved with UsingTask task. UsingTask is used to imported a new custom task you developed. It is not related to your issue.


Windows Live™: Keep your life in sync. Check it out.

Sunday, April 12, 2009

Error Sql-server express link to access database

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "DBName" returned message "Unspecified error".

Msg 7303, Level 16, State 1, Line 1

Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "DBName".
 
To work around this problem, follow these steps:
  1. Log on to the computer by using the SQL Server start up account.
  2. Create a folder named Temp in the operating system installation directory.
  3. Permit full access to a non-administrator account on the Temp folder.
  4. Set the value of the TEMP and TMP user variables of the SQL Server startup account to the newly created Temp folder. To do so, follow these steps:
    1. Right-click My Computer, and then click Properties.
    2. Click the Advanced tab, and then click Environmental Variables.
    3. In the User variables for Logon User list, click TEMP, and then click Edit.
    4. In theVariable Value box, type C:\Temp as the location of the new Temp folder, and then click OK.
    5. Repeat steps c and d to set the value of the TMP variable.
    6. Click OK two times.
  5. Log off, and then log on to the computer by using SQL Server startup account.
  6. Restart the SQL Server services.

Thursday, April 9, 2009

Transpose SQL-Server For sales data F4211


Select abac11,sdtrdj,sdglc,sddcto,sdshan,rtrim(wwgnnm)+' '+wwsrnm OwnerName,
SO_INCO= CASE WHEN SDDCTO='SO' and sdglc='INCO' Then Cast(sum(sdaexp/100) as decimal(10,2))  else 0 End,
SO_INPR= CASE WHEN SDDCTO='SO' and sdglc='INPR' Then Cast(sum(sdaexp/100) as decimal(10,2)) else 0 End,
SO_INCL= CASE WHEN SDDCTO='SO' and sdglc='INCL' Then Cast(sum(sdaexp/100) as decimal(10,2)) else 0 End,
SO_INEB= CASE WHEN SDDCTO='SO' and sdglc='INEB' Then Cast(sum(sdaexp/100) as decimal(10,2)) else 0 End,
SO_INC4= CASE WHEN SDDCTO='SO' and sdglc='INC4' Then Cast(sum(sdaexp/100) as decimal(10,2)) else 0 End,
SO_INQU= CASE WHEN SDDCTO='SO' and sdglc='INQU' Then Cast(sum(sdaexp/100) as decimal(10,2)) else 0 End,
TotalSO= CASE WHEN SDDCTO='SO' and sdglc in ('INPR','INEB','INC4','INCO','INCL','INQU')Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
SA_INCO= CASE WHEN SDDCTO='SA' and sdglc='INCO' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
SA_INPR= CASE WHEN SDDCTO='SA' and sdglc='INPR' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
TotalSA= CASE WHEN SDDCTO='SA' and sdglc in ('INPR','INCO')Then cast(sum(sdaexp/100) as decimal(10,2))  else 0 End,
SF_INCO= CASE WHEN SDDCTO='SF' and sdglc='INCO' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
SF_INPR= CASE WHEN SDDCTO='SF' and sdglc='INPR' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
SF_INCL= CASE WHEN SDDCTO='SF' and sdglc='INCL' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
SF_INEB= CASE WHEN SDDCTO='SF' and sdglc='INEB' Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End,
TotalSO= CASE WHEN SDDCTO='SF' and sdglc in ('INEB','INCO','INCL','INPR')Then Cast(sum(sdaexp/100)as decimal(10,2))  else 0 End
from proddta.f4211
left outer join proddta.f0111  on wwan8=sdshan
left outer join proddta.f0101  on aban8=sdshan
where sdnxtr=999 and sdlttr<>980 and sdkcoo=600 and sdlnty='S' and sddcto in('SO','SA','SF')
group by abac11,sdshan,wwgnnm,wwsrnm,sdtrdj,sdglc,sddcto

Wednesday, April 8, 2009

Find/Replace carriage return & line feed characters in Excel.

Find/Replace carriage return & line feed characters in Excel.
 
Try edit>repalce, find what hold down alt and type 010, release alt key,
do the same but use 013

Monday, April 6, 2009

Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Untitled Page</title>

<link href="<%= Page.ResolveUrl("~")%>default.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="<%= Page.ResolveUrl("~")%>cssverticalmenu.css" />

<script type="text/javascript" src="<%= Page.ResolveUrl("~")%>cssverticalmenu.js"></script>

</

head>

<

body>
Solution: Put your javascript tag after </head>
 

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Untitled Page</title>

</

head>

<link href="<%= Page.ResolveUrl("~")%>default.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="<%= Page.ResolveUrl("~")%>cssverticalmenu.css" />

<script type="text/javascript" src="<%= Page.ResolveUrl("~")%>cssverticalmenu.js"></script>

<

body>
 

 

Sunday, April 5, 2009

HtmlDecode asp.net C# code sample

Add following on top  HtmlDecode

using System.Text;
using System.IO;

Code

string strReview = nRev.InnerXml;
StringWriter writer = new StringWriter();
Server.HtmlDecode(strReview, writer);
strDet = writer.ToString();

Friday, April 3, 2009

URL Rewriting in ASP.NET -Live sample completed tested - 2.0/ 3.5, VB/ C#

URL rewrite Live sample completed tested


Down Load :- UrlRewritingNet.UrlRewriter.dll from http://www.urlrewriting.net/149/en/home.html
and copy this in bin folder and modify your web.config as following:-

look for the tag <!-- added for urlrewrite-->

to test use following:

Old URL:- http://localhost/svdl_1/prodpage.aspx?itemno=1605972002&strtitle=Twilight

New URL:- http://localhost/svdl_1/1605972002/Twilight.aspx

<?xml version="1.0"?>
<configuration>
<configSections>

<sectionGroup name="system.web.extensions"

type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup,

System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler"

type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"

allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"

type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization"

type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"

allowDefinition="Everywhere" />
<section name="profileService"

type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"

allowDefinition="MachineToApplication" />
<section name="authenticationService"

type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"

allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>

<section name="urlrewritingnet" restartOnExternalChanges="true" requirePermission ="false"

type="UrlRewritingNet.Configuration.UrlRewriteSection,UrlRewritingNet.UrlRewriter" />


</configSections>

<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>





<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,

PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"

type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0,

Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false"

type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0,

Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd"

type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0,

Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>


</httpHandlers>

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<!--added for urlrewrite-->
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule,

UrlRewritingNet.UrlRewriter" />
<!--end added for urlrewrite-->

</httpModules>
</system.web>

<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if

appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "truefalse"/>
-->

<!-- Uncomment these lines to enable the profile service. To allow profile properties to be

retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the

readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule,

System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd"

preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD"

path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>

<!--added for urlrewrite-->
<urlrewritingnet
rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
defaultPage = "default.aspx"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >

<rewrites>
<add name="Rule1" virtualUrl="^~/(.*)/(.*).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/prodpage.aspx?itemno=$1&amp;strtitle=$2"
ignoreCase="true" />

</rewrites>
</urlrewritingnet>

<!--added for urlrewrite-->

</configuration>

Thursday, April 2, 2009

Send email and Password Recovery Program -asp.net 2.0 C# sql-server

Send email for Password Recovery Program, Password from Database, C# asp.net 2.0, SQL-server

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

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

<head>
<title>Password Recover</title>

<meta name="robots" content="index, follow" />
<meta name="revisit-after" content="21 days" />
<meta name="author" content="" />
<meta name="copyright" content="" />
<meta name="rating" content="Global" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<meta name="abstract" content="" />
<link type="text/css" rel="stylesheet" href="css/layout.css" title="default" media="all" />

</head>

<body id="home">
<form id="form1" runat="server">
<div id="main-wrapper">

<div id="header">
        <a href="default.aspx">xxxxxxxx</a></div>
<div id="navigation"><center>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="White" Text="Recover Your Password   "></asp:Label>
        </center>
        
        </div>
<div id="content-wrapper"> &nbsp;<br />
        <table style="width:100%" bgcolor="White"><tr>
        <td style="height: 17px; width: 503px;">
            <div style="text-align: center">
                <table style="width: 70%" align="center">
                    <tr>
                        <td align="center" colspan="2">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td align="right" colspan="">
                            <asp:Label ID="Label2" runat="server" Text="Your Email ID:"></asp:Label></td>
                        <td align="left">
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" /></td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="txtmesge" runat="server" Width="331px"></asp:Label></td>
                    </tr>
                    <tr>
                        <td style="height: 17px">
                        </td>
                        <td style="height: 17px">
                        </td>
                    </tr>
                </table>
            </div>
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
        </td>
        </tr>
        </table>
        
        <br />
        <br />
 <div class="clear"></div>
   </div>
  <div id="feature-box">
      <br />
<div class="clear"></div>
</div><center><font size="1px" color="gray">
    © 2009 ABC,LLC</font></center></div>
</form>
</body>
</html>



using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

public partial class forpasswd : System.Web.UI.Page
    string struser;
    string strpasswd;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "" || TextBox1.Text == null)
        {
            txtmesge.Text = "Invalid Blanks.";
        }
        else
        {
            getpassdata();
        }
    }


    void getpassdata()
    {

        SqlConnection myConnection = new SqlConnection(ConnectionString);

        string strSQL = "select * FROM UserDetails WHERE UDEMAIL='" + TextBox1.Text + "'";
        string STRpass = "";
        SqlCommand cmd = new SqlCommand(strSQL, myConnection);
        myConnection.Open();
        SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        while (myReader.Read())
        {
            strpasswd = myReader["UDPASSWD"].ToString();
            struser = myReader["UDUSRID"].ToString();
           // Response.Write(strSQL);
           // Response.End();
            if (strpasswd.Trim() == null)
            {
                txtmesge.Text = "No Matches Found.";
            }
            else
            {
                sendemailpasswd();
            }

            break;
        }

        if (strpasswd == null)
        {
            txtmesge.Text = "No Matches Found, Please contact Admin.";
        }


        myReader.Close();
        myConnection.Close();
    }

    void sendemailpasswd()
    {
        
MailMessage objEmail = new MailMessage();
       objEmail.To = TextBox1.Text.Trim();
       objEmail.From = "YourEmail@abc.net";
       objEmail.Subject = "User Credentials For Gross Profit Reports";
       String EmailBody = "";
       EmailBody = "<html>";
       EmailBody += "<Body>";

       EmailBody += "<table  border=0 width=30% align=center bgcolor=#f1fff9 cellpadding=5 >";
       EmailBody += "<tr><td colspan=2 align=center bgcolor=#dff6d2 ><b>Your User Credentials:</b></td></tr>";
       EmailBody += "<tr><td >User:</td>";
       EmailBody += "<td align=left>" + struser + "</td></tr>";
       EmailBody += "<tr><td>Password:</td>";
       EmailBody += "<td align=left>" + strpasswd + "</td></tr>";
       
       EmailBody += "</table>";

       EmailBody += "</Body>";
       EmailBody += "</Html>";

       objEmail.Body = EmailBody;

         

        objEmail.Priority = MailPriority.High;
        objEmail.BodyFormat = MailFormat.Html;



        // Make sure you have appropriate replying permissions from your local system

        SmtpMail.SmtpServer = "mail.YOURDOMAIN.net";

        try
        {
            SmtpMail.Send(objEmail);

            txtmesge.Text = "User Credentials Sent.Check Your Email.";

            TextBox1.Text = "";
           



        }
        catch (Exception exc)
        {
            Response.Write("Send failure: " + exc.ToString());
        }

    }

    private string ConnectionString
    {
        get
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
            return connectionString;
        }
    }

 }