Monday, March 3, 2014

cookies

$("#btnLogin").click(function () {
        var hasError1 = true;
        if ($("#txtEmail").validationEngine('validateField', '#txtEmail')) {
            hasError1 = false;
        }
        if ($("#txtPassword").validationEngine('validateField', '#txtPassword')) {
            hasError1 = false;
        }
        if (hasError1 == true || hasError1 == "true") {
            if ($('#chkRememberEmail').attr('checked')) {
                $.cookie("cookieEmail", $('#txtEmail').val(), { expires: 30 });
                $.cookie("cookiepassword", $('#txtPassword').val(), { expires: 30 });
            }
            else {
                $.cookie('cookieEmail', null);
                $.cookie('cookiepassword', null);
            }
            user.Login();
            if (user.IsAuthenticate == 'true') {
                GetUserCompaniesMasterPage(user.SitePath);
                user.GetLoginUserFirstMenuPageID();
                Menu.PageID = user.PageId;
                Menu.SitePath = user.SitePath;
                Menu.GetPage();
            }
        }
        return false;
    });


----------------------------------------------------------------------------------------------

$("#spnLoginRemember").click(function () {
        var checkBoxes = $("#chkRememberEmail");
        checkBoxes.attr("checked", !checkBoxes.attr("checked"));
    });

----------------------------------------------------------------------------------------------------
Page load

 if ($.cookie("cookieEmail") != "" && $.cookie("cookiepassword") != "") {
        if ($.cookie("cookieEmail") != null && $.cookie("cookiepassword") != null) {
            $('#txtEmail').val($.cookie("cookieEmail"));
            $('#txtPassword').val($.cookie("cookiepassword"));
            $('#chkRememberEmail').attr('checked', 'checked');
        }
    }

----------------------------------------------------

$('#chkRememberEmail').click(function () {
        if ($('#chkbxremember').attr('checked')) {
            $('#chkbxremember').removeAttr('checked');
        }
        else {
            $('#chkbxremember').attr('checked', 'checked');
        }
    });

--------------------------------------------------------------------------------------------------------------------

Jquery.cookie1.js

/*jshint eqnull:true */
/*!
 * jQuery Cookie Plugin v1.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2011, Klaus Hartl
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/GPL-2.0
 */
(function($, document) {

    var pluses = /\+/g;
    function raw(s) {
        return s;
    }
    function decoded(s) {
        return decodeURIComponent(s.replace(pluses, ' '));
    }

    $.cookie = function(key, value, options) {

        // key and at least value given, set cookie...
        if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value == null)) {
            options = $.extend({}, $.cookie.defaults, options);

            if (value == null) {
                options.expires = -1;
            }

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }

            value = String(value);

            return (document.cookie = [
                encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path    ? '; path=' + options.path : '',
                options.domain  ? '; domain=' + options.domain : '',
                options.secure  ? '; secure' : ''
            ].join(''));
        }

        // key and possibly options given, get cookie...
        options = value || $.cookie.defaults || {};
        var decode = options.raw ? raw : decoded;
        var cookies = document.cookie.split('; ');
        for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
            if (decode(parts.shift()) === key) {
                return decode(parts.join('='));
            }
        }
        return null;
    };

    $.cookie.defaults = {};

})(jQuery, document);


-------------------------------------------------------------------------------------------------------------

handler.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Payroll.Handler
{
    ///
    /// Summary description for FileUploader
    ///

    public class FileUploader : IHttpHandler
    {


        //Rajveer Final Change
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpContext.Current.Response.ContentType = "text/HTML";

                string FName = "";
                string replaceundersore = "";
                string FileName = "";
                HttpFileCollection hfc = HttpContext.Current.Request.Files;

                string imagename = HttpContext.Current.Request.QueryString["filename"];
                var folderArray = imagename.Split('/');

                //if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Documentfiles/") + folderArray[0]))
                //{
                //    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Documentfiles/") + folderArray[0]);
                //}
                //if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Documentfiles") + folderArray[0] + '/' + folderArray[1]))
                //{
                //    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Documentfiles/") + folderArray[0] + '/' + folderArray[1]);
                //}

                //if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Documentfiles") + folderArray[0] + '/' + folderArray[1] + '/' + folderArray[2]))
                //{
                //    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Documentfiles/") + folderArray[0] + '/' + folderArray[1] + '/' + folderArray[2]);
                //}



                var array = imagename.Split('_');
                string path = HttpContext.Current.Server.MapPath("~/Resume/");
                if (!Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                for (int index = 0; index < hfc.Count; index++)
                {
                    HttpPostedFile hpf = hfc[index];
                    // change here for IE 8, as file name returns the full file path.

                    if (hpf.ContentLength > 0)
                    {
                        if (hpf.FileName.Contains(" "))
                        {
                            replaceundersore = hpf.FileName.Replace(" ", "-");
                        }
                        else
                        {
                            replaceundersore = hpf.FileName;
                        }

                        if (replaceundersore.Contains("_"))
                        {
                            FName = replaceundersore.Replace("_", "-");
                        }
                        else
                        {
                            FName = replaceundersore.Replace("_", "-");
                        }

                        int a = hpf.ContentLength;

                        //   string RandomNo = HttpContext.Current.Session["RandomNo"].ToString();
                        // FileName = RandomNo + FName;


                        FileName = FName;
                        string finalname = "";
                        // below code is for IE 8 as it fetch the full address of file.
                        int indexof = FileName.LastIndexOf("\\");
                        if (indexof != -1)
                        {
                            FileName = FileName.Substring(indexof + 1);
                        }

                        if (array[0] != null)
                        {
                            var fn = array[0].Substring(array[0].LastIndexOf('/') + 1);
                            finalname = fn + "_" + FileName;
                        }
                        else
                        {
                            finalname = FileName;
                        }

                        // below code is for IE 8 as it fetch the full address of file.
                        //var indexof = name2.lastIndexOf('\\');
                        //var fileName = '';
                        //if (indexof != -1) {
                        //    name2 = name2.substring(indexof + 1, name2.length)
                        //}


                        hpf.SaveAs(path + "/" + finalname);

                        // byte[] test = ReadImageFile(FileName);
                    }


                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}



--------------------------------

   

No comments:

Post a Comment

fill in blanks

ALL Reading Blanks: Special All approaches aim to increase blood flow to areas of tension and to release painful knots opt1 muscle kn...