Thursday, 18 April 2013

How can setup a friendly email name in the MailSetting section of web.config?


Well, in code you need to put the sender's name in quotes, followed by the e-mail address.

new SmtpClient(...).Send("\"John Smith\" jsmith@somewhere.com", ...);
And...it looks like you can encode it into the attribute too...

<smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">

CompareValidator for “dd/mm/yyyy” format

By default the ASP.Net CompareValidator does not work for dd/mm/yyyy format hence we will need to change the Culture property of the page to en-GB in the @Pagedirective of the ASP.Net Web Page as show below

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Request.aspx.cs" Inherits="Request" Culture = "en-GB"  %>

Wednesday, 17 April 2013

Standard Date Format in c#


DateTime dtStartDate, dtEndDate;
        string uname = null;
        string strStartDate, strEndDate;

   if (txtStartDate.Text == "")
            {
                strStartDate = string.Format("{0:d}", Convert.ToDateTime("01-01-1900"));
            }
            else
            {
                strStartDate = string.Format("{0:d}", Convert.ToDateTime(txtStartDate.Text));
            }
            if (txtEndDate.Text == "")
            {
                strEndDate = string.Format("{0:d}", Convert.ToDateTime("01-01-2500"));
            }
            else
            {
                strEndDate = string.Format("{0:d}", Convert.ToDateTime(txtEndDate.Text));
            }

            dtStartDate = Convert.ToDateTime(strStartDate);
            dtEndDate = Convert.ToDateTime(strEndDate);



  strStartDate= dtStartDate.ToString("dd/MM/yyyy", new CultureInfo("en-US"))
  strEndDate= dtEndDate.ToString("dd/MM/yyyy", new CultureInfo("en-US"))

Friday, 5 April 2013

Wednesday, 13 March 2013

Uploading file with Progress Bar


   <script language="javascript" type="text/javascript">
        var size = 2;
        var id = 0;

        function ProgressBar() {          
                document.getElementById("divProgress").style.display = "block";
                document.getElementById("divUpload").style.display = "block";
                id = setInterval("progress()", 20);
                return true;        

        }

        function progress() {
            size = size + 1;
            if (size > 299) {
                clearTimeout(id);
            }
            document.getElementById("divProgress").style.width = size + "pt";
            document.getElementById("<%=lblPercentage.ClientID %>").firstChild.data = parseInt(size / 3) + "%";
        }

    </script>


 <asp:Button ID="btnAddImage" runat="server" Text="Upload File"OnClientClick="return ProgressBar()" OnClick="btnAddImage_Click" />

<div id="divUpload" style="display: none">
                        <div style="width: 300pt; text-align: center;">
                            Uploading...</div>
                        <div style="width: 300pt; height: 20px; border: solid 1pt gray">
                            <div id="divProgress" runat="server" style="width: 1pt; height: 20px; background-color: Blue;
                                display: none">
                            </div>
                        </div>
                    </div>





c# search in google using search text as parameter

http://www.google.com/search?q=query

Tuesday, 12 March 2013