Tuesday, 24 July 2012

image slider in asp.net link

image slider in asp.net link
http://www.ajaxshake.com/en/JS/125810/image-slider.html


Animation
http://www.ajaxshake.com/en/JS/12601/animation.html


LightBox
http://www.ajaxshake.com/en/JS/12261/lightbox.html
http://www.ajaxshake.com/demo/EN/1021/a0942484/how-to-create-a-lightbox-using-css3-css3lightbox.html


model windows
http://www.ajaxshake.com/en/JS/12741/modal-windows.html


image and photo
http://www.ajaxshake.com/en/JS/12631/images-and-photos-.html



JQuery Image Slider by using ASP.NET Listview, ArrayList


ajex slid show
http://technico.qnownow.com/2012/05/09/ajax-slide-show-extender-control-in-asp-net/




Monday, 23 July 2012

Uploading Zip File in ASP.NET

Step 1

Create A one Default Page Which Contain One Uploader and SubmitButton

Step 2

C# code on Submit Button.
protected void button_Click(object sender, EventArgs e)
{
    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Class"].ConnectionString)) //SQl Server ConnectionString
    {
    if (FileUpload1.HasFile)
    {
    //SqlDataSource1.Insert();
    string filename = Path.GetFileName(FileUpload1.FileName);
    string fullpath = Server.MapPath("~/FileUpload/ZipFile/") + filename; //Zip File Save On ServerSide.
    if (File.Exists(fullpath))
    {
        File.Delete(fullpath);
    }
    FileUpload1.SaveAs(fullpath);
    ArrayList zippedList = UnZipFile(fullpath);  //method for Extracted the Zip File.

    foreach (string filepath in zippedList)
    {
        DataTable SheetNames = GetExcelSheetNames(filepath);   //Get All SheetName contain By individual ExcelSheet.

        foreach (DataRow dr in SheetNames.Rows)
        {
        string strFileType = System.IO.Path.GetExtension(filepath.ToLower());
        string sSourceConstr = String.Empty;
 
        if (strFileType.Trim() == ".xls")
        {
        sSourceConstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + filepath + "; Extended Properties=\"Excel 8.0; HDR=Yes; IMEX=2\"";
        }
        else if (strFileType.Trim() == ".xlsx")
        {
        sSourceConstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + filepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
        }
 
        string sDestConstr = ConfigurationManager.ConnectionStrings["Class"].ConnectionString;
        OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
        using (sSourceConnection)
        {
        sSourceConnection.Open();
 
        string sql = "select * from [" + dr["SheetName"].ToString() + "]"; //"select * from $",sheet
        OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
 
        OleDbDataAdapter da = new OleDbDataAdapter();
        da = new OleDbDataAdapter(command);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables.Count > 0)
        {
           //here Your Code To Save in The Database.
    //i hope that you know that. the data of excel Sheet stored on database.
        }
        }
        }
        }
    }
    }
    }
}

Step 3

UnZipFile(fullpath); Method

We used this method to extract the zip file.

C# code is:
  private ArrayList UnZipFile(string fullpath)
    {
    ArrayList pathList = new ArrayList(); //contain the number of Excel file.
    try
    {
    if (File.Exists(fullpath))
    {
    string baseDirectory = Path.GetDirectoryName(fullpath);
 
    using (ZipInputStream ZipStream = new ZipInputStream(File.OpenRead(fullpath)))
    {
        ZipEntry theEntry;
        while ((theEntry = ZipStream.GetNextEntry()) != null)
        {
        if (theEntry.IsFile)
        {
        if (theEntry.Name != "")
        {
        string strNewFile = @"" + baseDirectory + @"\Excel\" + theEntry.Name;
        if (File.Exists(strNewFile))
        {
        //continue;
        }
 
        using (FileStream streamWriter = File.Create(strNewFile))
        {
        pathList.Add(strNewFile);
        int size = 2048;
        byte[] data = new byte[2048];
        while (true)
        {
            size = ZipStream.Read(data, 0, data.Length);
            if (size > 0)
            streamWriter.Write(data, 0, size);
            else
            break;
        }
        streamWriter.Close();
        }
        }
        }
        else if (theEntry.IsDirectory)
        {
        string strNewDirectory = @"" + baseDirectory + @"\" + theEntry.Name;
        if (!Directory.Exists(strNewDirectory))
        {
        Directory.CreateDirectory(strNewDirectory);
        }
        }
        }
        ZipStream.Close();
    }
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }
    return pathList;
    }

Step 4

Method for get ExcelSheet Name is:
GetExcelSheetNames(filepath);
C# Code For The GetExcelSheetNames Are:
private DataTable GetExcelSheetNames(string filepath)
    {
    OleDbConnection objConn = null;
    System.Data.DataTable dt = null;
    String[] excelSheets;
 
    try
    {
 
    string strFileType = System.IO.Path.GetExtension(filepath.ToLower());
    string connString = String.Empty;
    if (strFileType.Trim() == ".xls")
    {
    connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + filepath + "; Extended Properties=\"Excel 8.0; HDR=Yes; IMEX=2\"";
    }
    else if (strFileType.Trim() == ".xlsx")
    {
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + filepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
    }
 
    // Create connection object by using the preceding connection string. 
    objConn = new OleDbConnection(connString);
 
    // Open connection with the database. 
    objConn.Open();
 
    // Get the data table containg the schema guid. 
    dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
 
    if (dt == null)
    {
    return null;
    }
 
    DataTable table = new DataTable();
    table.Columns.Add("SheetName");
 
    // Add the sheet name to the string array. 
    foreach (DataRow row in dt.Rows)
    {
    DataRow dr = table.NewRow();
    if (row["TABLE_NAME"].ToString().EndsWith("_"))
    {
        continue;
    }
    else
    {
        string name = row["TABLE_NAME"].ToString();
        dr["SheetName"] = name.Replace("'", "");
        table.Rows.Add(dr);
    }
    }
    //foreach (DataRow row in table.Rows)
    //{
    //    string row = row[SheetName].ToString();
    //}
    return table;
    }
 
    catch (Exception ex)
    {
    throw ex;
    }
    finally
    {
    // Clean up. 
    if (objConn != null)
    {
    objConn.Close();
    objConn.Dispose();
    }
    if (dt != null)
    {
    dt.Dispose();
    }
    }
    }
Exactly how this works:

Upload the zip file using the uploader. After uploading, it will first save on server side. After that, we will pass the whole path of that zip to unzip the file.

How UnzipMethod Work

For that, we have one arraylist, i.e., pathlist contains all Excel files which are in zip folder.

ZipInputStream

This is used to open and read the zip folder. Using this, we can get all files present in that zip file.
ZipEntry theEntry = ZipStream.GetNextEntry())
Get the file from the zip.
Then using FileStream streamWriter, we create the extracted file and store in pathlist and return the pathlist.

How GetSheetName Work

One Excel Sheeet contains a number of sheets. Now we want all sheets to read and then save on database. Therefore we used this method to get all sheetname from that particular Excel sheet.
 dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
This is used to get all sheet names.

After that, it is important that:
if (row["TABLE_NAME"].ToString().EndsWith("_"))
    {
        continue;
    }
    else
    {
        string name = row["TABLE_NAME"].ToString();
        dr["SheetName"] = name.Replace("'", "");
        table.Rows.Add(dr);
    }
This code is important because the Excel sheet name contains some garabage sheet name with ends with '_' operator. That's why we used the above code to remove that sheet name.
 

Saturday, 21 July 2012

div inner html all data taken in string


StringWriter sw = new StringWriter();
            HtmlTextWriter w = new HtmlTextWriter(sw);
            dvEDs.RenderControl(w);
            string s = sw.GetStringBuilder().ToString();


//--------

<div id="dvEDs" runat="server">
        <table width="100%" bgcolor="lime" align="left">
         
       <tr><td colspan="2">
           <img src="images/arrow.gif" /> Event Title &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;: <asp:Label ID="lblEtitle" runat="server" CssClass="he testimonial" Text='<%#Bind("event_title")%>' Font-Bold="True"></asp:Label></td></tr>
       <tr bgcolor="#FFF2F2"><td><img src="images/arrow.gif" /> Event Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;: <asp:Label ID="lblEDate" runat="server" Text='<%#Bind("event_date")%>'></asp:Label></td><td><img src="images/arrow.gif" />
           Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <asp:Label ID="lblETime" runat="server" Text='<%#Bind("event_time")%>'></asp:Label></td></tr>
       <tr bgcolor="#F1F4FE"><td><img src="images/arrow.gif" /> Event End Date &nbsp;&nbsp;&nbsp; &nbsp;: <asp:Label ID="lblEdEnd" runat="server" Text='<%#Bind("event_date_end")%>'></asp:Label></td><td><img src="images/arrow.gif" />
           Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <asp:Label ID="lbleEndTime" runat="server" Text='<%#Bind("event_time_end")%>'></asp:Label></td></tr>      
       <tr><td><img src="images/arrow.gif" /> Entry By&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; : <asp:Label ID="lblentryBy" runat="server" Text='<%#Bind("entry_by")%>'></asp:Label></td><td><img src="images/arrow.gif" /> Attendit : <asp:Label ID="lblAttendit" runat="server" Text='<%#Bind("Attendit")%>'></asp:Label></td></tr>
       <br />
       <tr><td colspan="2"><img src="images/arrow.gif" /> Event Description&nbsp;&nbsp; :<span style="padding-left:1px;">
           <asp:Label ID="Label1" runat="server"
               Text='<%# Bind("event_dsn") %>' CssClass="tweet_text"></asp:Label></span></td></tr>
       </table>
       </div>
//----------------
output//----------------


<div id="ctl00_ContentPlaceHolder1_dvEDs">
        <table width="100%" bgcolor="lime" align="left">
         
       <tr><td colspan="2">
           <img src="images/arrow.gif" /> Event Title &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;: <span id="ctl00_ContentPlaceHolder1_lblEtitle" class="he testimonial" style="font-weight:bold;">mahesh area</span></td></tr>
       <tr bgcolor="#FFF2F2"><td><img src="images/arrow.gif" /> Event Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;: <span id="ctl00_ContentPlaceHolder1_lblEDate">Jul 18, 2012</span></td><td><img src="images/arrow.gif" />
           Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <span id="ctl00_ContentPlaceHolder1_lblETime">6:11:00 PM          </span></td></tr>
       <tr bgcolor="#F1F4FE"><td><img src="images/arrow.gif" /> Event End Date &nbsp;&nbsp;&nbsp; &nbsp;: <span id="ctl00_ContentPlaceHolder1_lblEdEnd">Jul 19, 2012</span></td><td><img src="images/arrow.gif" />
           Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <span id="ctl00_ContentPlaceHolder1_lbleEndTime">7:11:00 PM          </span></td></tr>      
       <tr><td><img src="images/arrow.gif" /> Entry By&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; : <span id="ctl00_ContentPlaceHolder1_lblentryBy">mahesh</span></td><td><img src="images/arrow.gif" /> Attendit : <span id="ctl00_ContentPlaceHolder1_lblAttendit">aytreayr</span></td></tr>
       <br />
       <tr><td colspan="2"><img src="images/arrow.gif" /> Event Description&nbsp;&nbsp; :<span style="padding-left:1px;">
           <span id="ctl00_ContentPlaceHolder1_Label1" class="tweet_text">sub sstring<br /></span></span></td></tr>
       </table>
       </div>


Thursday, 19 July 2012

asp.net login and logout code with clear page catch and history


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Data.SqlClient;

namespace The_Kila.Admin
{
    public partial class Default1 : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kilaCon"].ToString());
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {//---check user login info
            try
            {
                if ((!string.IsNullOrEmpty(txtUserName.Text)) && (!string.IsNullOrEmpty(txtPassword.Text)))
                {


                    string cLogin = "select count(*) from login where username='" + txtUserName.Text.TrimStart().TrimEnd() + "' and password='" + txtPassword.Text.Trim() + "'";
                    SqlCommand cmd = new SqlCommand(cLogin, con); con.Open();
                    Int32 nUser = Convert.ToInt32(cmd.ExecuteScalar()); con.Close();

                    if (nUser > 0)
                    {
                        CreateCookiee();
                        Response.Redirect("~/Admin/adminHome.aspx");
                    }
                    else
                        Response.Write("<script>alert('Invalid UserName Or Password')</script>");
                }
                else
                    Response.Write("<script>alert('Please fill UserName and Password')</script>");
            }
            catch (Exception)
            {
                // Response.Redirect("~/Admin/Default.aspx");
                //throw;
            }
           
        }
        private void CreateCookiee()
        {//--login user create cookie
            HttpCookie _logCookie = new HttpCookie("userInfo");
            _logCookie["loginName"] = txtUserName.Text.TrimStart().TrimEnd();
           // _logCookie["password"] = txtPassword.Text.TrimStart().TrimEnd();
            _logCookie.Expires.AddMinutes(30);
            Response.Cookies.Add(_logCookie);
        }

    }
}
//--------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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;

namespace The_Kila.Admin
{
    public partial class AdminMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    HttpCookie _InfoCookie = new HttpCookie("userInfo");
                    if (_InfoCookie != null && (!string.IsNullOrEmpty(Convert.ToString(Request.Cookies["userInfo"]["loginName"]))))
                    {
                        string cLoginUser = Server.HtmlEncode(Request.Cookies["userInfo"]["loginName"]);
                        lblWelcomeLogin.Text = "Welcome -" + cLoginUser;
                    }
                    else
                        Response.Redirect("http://thekila.in/");
                }
            }
            catch (Exception)
            {
                Response.Redirect("~/Admin/Default.aspx");
               // throw;
            }
            
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {//--loout
                        
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1);
            Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(-1);
            HttpCookie aCookie = Request.Cookies["userInfo"];
            aCookie.Values.Remove("loginName");

            Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();

            Response.Redirect("~/Admin/Default.aspx");
        }
    }
}

scroll go to top and go to bottom page



<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Scroll to Bottom or Top - DevCurry.com</title>
    <script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js">
    </script>
     <script type="text/javascript" language="javascript">
         $(function () {
             $('#scrlBotm').click(function () {
                 $('html, body').animate({
                     scrollTop: $(document).height()
                 },
                 1500);
                 return false;
             });

             $('#scrlTop').click(function () {
                 $('html, body').animate({
                     scrollTop: '0px'
                 },
                 1500);
                 return false;
             });
         });
    </script>
</head>
<body>
    <a id="scrlBotm" href="#">Scroll to Bottom</a> 
    <div style="height:1000px"></div>
    <a id="scrlTop" href="#">Scroll to Top</a>
</body>
</html>

//-------------second exp


<!DOCTYPE html>
<html>
<body>

<p>
<a href="#C4">See also Chapter 3</a>
</p>

<p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>

<h2><a name="C4">Chapter 3</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 4</a></h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 5</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 6</h2>

Tuesday, 17 July 2012

sql query for sub string no of charter lenth data pic


SELECT SUBSTRING(event_title,CHARINDEX(N'Þ',event_title),5) as [String] from events


result -thank

sql query for sub string no of charter lenth data pic 

Thursday, 12 July 2012

facebook login account information get in your asp.net page


 create app and integrate facebook login in website based on previous post. Once set up is completed check your aspx page and observe script in your page in that we have function

FB.api('/me', function(me) {
if (me.name) {
document.getElementById('auth-displayname').innerHTML = me.name;
}
})
FB.api function is used to get basic details (Name, profile image, gender, user id, friends list, any information we shared publically) of logged in user from facebook.

If you need access to more information, such as the user's email address, etc. you must requestpermissions for this information. For that we need to add permission to scope attribute of the Login Button and our FB.api function will be like this

var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
FB.api('/me', function(me) {
document.getElementById('auth-displayname').innerHTML = me.name;
document.getElementById('Email').innerHTML = me.email;
document.getElementById('profileImg').src = uid;
})
By using above method we can get name, email, profile image for that Our scope attribute of login button will be like this

<div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">Login with Facebook</div>
</div>
Here I am getting only user email address if you want more information then you need to get permission for other objects for that check this link scope permission reference.

After make all our code modifications that would be like this


<html>
<head>
<title>Facebook Get Logged in User Details UserName,Email,Profile Image</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
// Load the SDK Asynchronously
(function(d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));

// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId: '198191300293654', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true  // parse XFBML
});

// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
FB.api('/me', function(me) {
document.getElementById('auth-displayname').innerHTML = me.name;
document.getElementById('Email').innerHTML = me.email;
document.getElementById('profileImg').src = uid;
})
document.getElementById('auth-loggedout').style.display = 'none';
document.getElementById('auth-loggedin').style.display = 'block';
} else {
// user has not auth'd your app, or is not logged into Facebook
document.getElementById('auth-loggedout').style.display = 'block';
document.getElementById('auth-loggedin').style.display = 'none';
}
});
$("#auth-logoutlink").click(function() { FB.logout(function() { window.location.reload(); }); });
}
</script>
<h1>
Facebook Login Authentication Example</h1>
<div id="auth-status">
<div id="auth-loggedout">
<div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">Login with Facebook</div>
</div>
<div id="auth-loggedin" style="display: none">
Name: <b><span id="auth-displayname"></span></b>(<a href="#" id="auth-logoutlink">logout</a>)<br/>
Email: <b><span id="Email"></span></b><br />
Profile Image: <img id="profileImg" />
</div>
</div>
</body>
</html>
Now run your application and check the output that would be like this

Demo