Thursday, 12 December 2013

Save image from oneLocation to Another Location Using C# Asp.Net

byte[] bitmapdata;
    string strFilePath = "";
    protected void Button1_Click(object sender, EventArgs e)
    {
        string path = @"F:\bhasker\web\";
        strFilePath = path;
        Bitmap bmp = new Bitmap(@"F:\bhasker\web\publish\images.bmp");
        MemoryStream ms = new MemoryStream();
        bmp.Save(ms, ImageFormat.Bmp);
        strFilePath += bmp + ".jpg";
        bitmapdata = ms.ToArray();
        MemoryStream ms1 = new MemoryStream(bitmapdata);
        Bitmap bmp1 = new Bitmap(ms1);
        string realPath = strFilePath;
        System.Drawing.Image img = ResizeImage(bmp1, 75);
        img.Save(Server.MapPath("~/" + realPath));
        Image1.ImageUrl = Convert.ToString(bmp1);
    }

    private System.Drawing.Image ResizeImage(System.Drawing.Image bmp23, int imageWidth)
    {
        System.Drawing.Image image;
        image = bmp23.GetThumbnailImage(imageWidth, 60, null, IntPtr.Zero);
        return image;
    }
    S

Tuesday, 3 December 2013

Date time display

function date_time(id)
    {
        date = new Date;
        year = date.getFullYear();
        month = date.getMonth();
        months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'Jully', 'August', 'September', 'October', 'November', 'December');
        d = date.getDate();
        day = date.getDay();
        days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
        h = date.getHours();
        suffix = "AM";
        if (h >= 12) {
       suffix = "PM";
       h = h - 12;
   }
   if (h == 0) {
       h = 12;
   }
        m = date.getMinutes();
        if(m<10)
        {
                m = "0"+m;
        }
        s = date.getSeconds();
        if(s<10)
        {
                s = "0"+s;
        }
        result=''+days[day]+', '+months[month]+' 0'+d+', '+year+' '+'Time : '+h+':'+m+':'+s+' '+suffix;
        document.getElementById(id).innerHTML = result;
        setTimeout('date_time("'+id+'");','1000');
        return true;
    }



 <td  colspan="3" style="width:340px">
                       <span id="date_time" class="date_time"></span>
                            <script type="text/javascript">window.onload = date_time('date_time');</script>              
                    </td>

Get Session Timeout value from web.config and decrement this value.

<script type="text/javascript" language="javascript">
        sessionTimeout = <%= Session.Timeout %> ;
        now = new Date();
        newtime = now.setMinutes(now.getMinutes() + parseInt(sessionTimeout));
    function Session_Expiry(session1) {
        now = new Date();
        diff = newtime - now;
        days = Math.floor(diff / (1000 * 60 * 60 * 24));
        hours = Math.floor(diff / (1000 * 60 * 60));
        mins = Math.floor(diff / (1000 * 60));
        secs = Math.floor(diff / 1000);
        mm = mins - hours * 60;
        ss = secs - mins * 60;
        if(mm<10 && mm>=0)
        {
            mme='0'+mm;
        }
        else
        {
            mme=mm;
        }
        if(ss<10 && ss>=0)
        {
            sse='0'+ss;
        }
        else
        {
            sse=ss;
        }
        sessionresult ='Session will expiry in '+ mme + ':' + sse + ' Secs';
        document.getElementById(session1).innerHTML = sessionresult;
        if(secs<=0)
        {
           window.location.href='Login.aspx';
        }
        setTimeout('Session_Expiry("'+session1+'");','1000');
        return true;
    }
</script>


in body

<td style="width:240px">
                 <span id="Session_Expiry" class="Session_Expiry"></span>
                            <script type="text/javascript">window.onload = Session_Expiry('Session_Expiry');</script>  
                </td>