Thursday, 26 June 2014

Download file in zip format


using Ionic.Zip;

protected void btnDownload_Click(object sender, EventArgs e)
    {
        using (ZipFile zip = new ZipFile())
        {
            foreach (GridViewRow gvrow in gvDetails.Rows)
            {
                CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
                if (chk.Checked)
                {
                    string fileName = gvrow.Cells[1].Text;
                    string filePath = Server.MapPath("~/UploadedResumeByUsers/" + fileName);
                    zip.AddFile(filePath, "files");
                }
            }
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");
            Response.ContentType = "application/zip";
            zip.Save(Response.OutputStream);
            Response.End();
        }
    }    

Thursday, 12 June 2014

Excel Insert, Update, Delete by .net

--------aspx-----------
 <asp:Button ID="create" runat="server" Text="create" /><br />
        <asp:Button ID="insert" runat="server" Text="insert" /><br />
        <asp:Button ID="select1" runat="server" Text="select" /><br />
        <asp:Button ID="update" runat="server" Text="update" /><br />
----------------------cs---------------
Imports System.Data.OleDb
Partial Class excel_update
    Inherits System.Web.UI.Page
    'Private m_sConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\ExcelData2.xls;Extended Properties=Excel 8.0"
    'Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\ExcelData2.xls;Extended Properties=Excel 8.0"
    'Private m_sAction As String

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

     
    End Sub
    Private Function CreateConnString(ByVal Str As String) _
        As String

        Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
        + Str + ";Extended Properties=""Excel 8.0;HDR=YES;"""


    End Function
     ';;;;;;;;;;;;
    Protected Sub create_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles create.Click
        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand

        Conn.ConnectionString = CreateConnString("D:\RND\test\excel\Book1.xls")
        Comm.Connection = Conn
        Comm.CommandText = _
         "Create Table MySheet (F1 char(255), F2 char(255))"

        Try
            Conn.Open()
            Comm.ExecuteNonQuery()
            MsgBox("Created.")
            Conn.Close()
        Catch ex As Exception
            MsgBox("Error.")
            Conn.Close()
        End Try
    End Sub

    Protected Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insert.Click
        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand

        Conn.ConnectionString = CreateConnString("D:\RND\test\excel\Book1.xls")
        Comm.Connection = Conn
        Comm.CommandText = _
         "Insert INTO [MySheet$] (F1, F2) Values ('1','2')"

        Try
            Conn.Open()
            Comm.ExecuteNonQuery()
            MsgBox("Inserted.")
            Conn.Close()
        Catch ex As Exception
            MsgBox("Error.")
            Conn.Close()
        End Try
    End Sub

    Protected Sub select1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles select1.Click
        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand
        Dim DReader As OleDbDataReader
        Dim Str As String = ""

        Conn.ConnectionString = CreateConnString("D:\RND\test\excel\Book1.xls")
        Comm.Connection = Conn
        Comm.CommandText = "Select [F1], [F2] From [MySheet$]"

        Try
            Conn.Open()
            DReader = Comm.ExecuteReader

            Do While DReader.Read
                Str = Str + vbCrLf + DReader.GetString(0) _
                + " , " + DReader.GetString(1)
            Loop

            MsgBox(Str)
            DReader.Close()
            Conn.Close()
        Catch ex As Exception
            MsgBox("Error.")
            Conn.Close()
        End Try

    End Sub

    Protected Sub update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles update.Click

        Dim Conn As New OleDbConnection
        Dim Comm As New OleDbCommand

        Conn.ConnectionString = CreateConnString("D:\RND\test\excel\Book1.xls")
        Comm.Connection = Conn
        Comm.CommandText = _
         "Update [MySheet$] SET F1 = 'pramod' Where F2 = '2'"

        Try
            Conn.Open()
            Comm.ExecuteNonQuery()
            MsgBox("Updated.")
            Conn.Close()
        Catch ex As Exception
            MsgBox("Error.")
            Conn.Close()
        End Try
    End Sub
End Class

Dictionary use for filter by Alfabet .net

--------------aspx---------------
 <div>
    <asp:Repeater ID="FilteringUI"  runat="server" OnItemCommand="FilteringUI_ItemCommand">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkFilter" Text='<%# Container.DataItem %>' CommandName='<%# Container.DataItem %>'>
                </asp:LinkButton>
            </ItemTemplate>
            <SeparatorTemplate>
                |</SeparatorTemplate>
        </asp:Repeater>
    </div>
    <asp:GridView ID="gridUsers" runat="server">
        </asp:GridView>
--------------------cs--------------------------------
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;

public partial class birla_xml_loc_panel_Directory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindFilteringUI();
    }
    private void BindFilteringUI()
    {
        string[] filterOptions = { "All", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        FilteringUI.DataSource = filterOptions;
        FilteringUI.DataBind();
    }
    protected void FilteringUI_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "All")
            this.UsernameToMatch = string.Empty;
        else
            this.UsernameToMatch = e.CommandName;
        BindUserAccounts();
    }
     private void BindUserAccounts()
    {
       
        if (this.UsernameToMatch == "")
        {SqlConnection con =new SqlConnection ("server=10.0.0.11;database=planetm;uid=sa;pwd=sa;");
            DataSet ds=new DataSet ();
            SqlDataAdapter da=new SqlDataAdapter ("select username,lastname from UserProfile ",con);
            da.Fill (ds);
            gridUsers.DataSource = ds;
            gridUsers.DataBind();
        }
        else
        {
            string str = this.UsernameToMatch;
            SqlConnection con = new SqlConnection("server=10.0.0.11;database=planetm;uid=sa;pwd=sa;");
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select username,lastname from UserProfile where username like '" + str + "%' ", con);
            da.Fill(ds);
            gridUsers.DataSource = ds;
            gridUsers.DataBind();
        }
    }
    private string UsernameToMatch
    {
        get
        {
            object o = ViewState["UsernameToMatch"];
            if (o == null)
                return string.Empty;
            else return (string)o;
        }
        set
        {
            ViewState["UsernameToMatch"] = value;
        }
    }
}

Two Query one No column in VB.net

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=pramod;Integrated Security=True;")

        Dim ds As New DataSet
        Dim dsa As New DataSet
        Dim dr As New SqlDataAdapter("SELECT count(name)+ 1+ROW_NUMBER()  OVER (ORDER BY name) AS id ,name FROM test1 group by name; SELECT ROW_NUMBER()  OVER (ORDER BY lastname) AS id, lastname FROM test2; ", con)

        dr.Fill(ds)

        Dim i As Integer = 0
        Dim table As DataTable = ds.Tables(0)
        table.Columns.Add(New DataColumn("no", GetType(Integer)))
        Dim rowcount As Integer = table.Rows.Count
        Dim k As Integer = 1
        While (i < rowcount)
            table.Rows(i)("no") = k
            i = i + 1
            k = k + 1

        End While

        GridView1.DataSource = table
        GridView1.DataBind()
        Dim j As Integer = 0
        Dim tablea As DataTable = ds.Tables(1)
        tablea.Columns.Add(New DataColumn("no", GetType(Integer)))
        rowcount = tablea.Rows.Count
        While (j < rowcount)
            tablea.Rows(j)("no") = k
            k = k + 1
            j = j + 1
        End While
        GridView2.DataSource = tablea
        GridView2.DataBind()
       

    End Sub

Monday, 9 June 2014

Create Global Variable in xsl and value assign by c sharp function in xsl all those thing in one xsl

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:tns="urn:thisnamespace:tns"  exclude-result-prefixes="tns msxsl"
                >
<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>
  <xsl:param name="PageUrl" />
  <xsl:param name="url"/>
  <xsl:param name="hanmant"/>
  <xsl:param name="date"  />

  <msxsl:script language="C#"   implements-prefix="tns">
     <msxsl:assembly name="System" />
     <msxsl:using namespace="System" />
     <msxsl:assembly name="System.Web" />
     <msxsl:using namespace="System.Web" />
     <msxsl:assembly name="System.Configuration"/>
     <msxsl:using namespace="System.Configuration"/>
     <msxsl:using namespace="System.Xml"/>
     <msxsl:using namespace="System.Xml.XPath"/>
    <msxsl:assembly name="System.Data"/>
    <msxsl:using namespace="System.Data"/>
  <msxsl:using namespace="System.Data.SqlClient"/>
   <![CDATA[
   
  public string databaseaccess()
    {
         String query, kk= "<table border='1px'><tr><td>Sr no.</td><td>Name</td><td>File Path</td></tr>";
      try
                {
        SqlConnection con = new SqlConnection("Data Source=INMUBLBW0709\\SQLEXPRESS2008;Initial Catalog=idfcmf;Persist Security Info=True;User ID=sa;Password=admin123");
        con.Open();
         int i=0;
        query = "select * from DownloadCenter";
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader dr;
        //cmd.Parameters.Add("@id", SqlDbType.Int).Value = name.Value;
        //cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = address.Value;
        dr = cmd.ExecuteReader();
        dr.Read();
        while (dr.Read())
        {
          i=i+1;
            kk = kk+"<tr><td> "+i+" </td><td>"+ dr["Title"].ToString()+"</td><td>"+ dr["uploadfile"].ToString()+"</td></tr>";
            //Text3.Value = dr(1)
        }
         kk = kk + "</table>";
             }
        catch (Exception ex)
        {
            return ex.ToString();
        }
         return kk;
       

    }
   
 public string readxml()
    {
        string xmlstring = "<table border='1px'><tr><td>Sr no.</td><td>Name</td></tr>";
        int i=0;
        string link1 = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["NavXML"]);
        try
        {
            XmlDocument xmlDoc = new XmlDocument();
           xmlDoc.Load(link1);
         
            XmlNode titleNode = xmlDoc.SelectSingleNode("site//global");

            foreach (XmlNode xn in titleNode)
            {
                  i=i+1;
                try
                {
                  xmlstring = xmlstring +"<tr><td> "+i+" </td><td>"+ xn.Attributes["caption"].Value +"</td></tr>";//innertext
                }
                catch
                {
                }

            }
            xmlstring = xmlstring + "</table>";

        }
        catch (Exception ex)
        {
            return ex.ToString();
        }

        return xmlstring;
    }
   
    public string LinkFile()
    {
         string link = System.Configuration.ConfigurationManager.AppSettings["SiteURL"];
         return link;
    }
   
    public double calculation(double radius){
       double pi = 3.14;
       double circ = pi*radius*2;
       return circ;
     }
 
   public string circumference()
      {
      DateTime date = DateTime.Now;
        string vv =date.ToString()+HttpContext.Current.Request.Url.AbsoluteUri.ToString().ToLower().Replace("http://"+HttpContext.Current.Request.Url.Authority.ToString(),"");// date.ToString();
         return vv;
      }
      public string mydate()
      {
      DateTime date = DateTime.Now;
        string vv = date.ToString();
         return vv;
      }
]]>
 
  </msxsl:script>
 
<xsl:variable name="cdtitle">
  <xsl:value-of select="tns:readxml()"/>
</xsl:variable>
  <xsl:param name="date1"  >
    <xsl:value-of select="tns:mydate()"/>
  </xsl:param>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />


  <xsl:template match="/">
    <xsl:text disable-output-escaping="yes">
<![CDATA[
       <script type="text/javascript">
     

        function callme() {
          alert('pramod');
    }
</script>
]]>
</xsl:text>
  <br/><xsl:value-of select="$cdtitle"/><br/>
    <div onclick="callme();">
      <xsl:value-of select="tns:circumference()"/></div>


    after load Request.Url.ToString():=  <input type="button" value="Stampa" onclick="callme();"></input>
 
     <xsl:value-of select="$hanmant"/>  <xsl:value-of select="$currentPage"/>
    <xsl:value-of select="$date1"/>new
    <xsl:apply-templates select="." mode="GetData" />
  </xsl:template>
  <xsl:template match="site" mode="GetData">
 
    <xsl:for-each select="main/page">
      11<xsl:value-of select="current()"/>22
      <ul class="col{position()}">
        <li>
          <span>

            pramod:--
         <xsl:value-of select="$date"/>
            --tests
            <xsl:value-of select="@caption"/>
          </span>
          <span>
           
            <xsl:value-of select="@caption"/>
          </span>
          <xsl:call-template name="drawChildNodes">
            <xsl:with-param name="parentnode" select="."/>
          </xsl:call-template>
        </li>
      </ul>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="drawChildNodes">
    <xsl:param name="parentnode"></xsl:param>

    <xsl:if test="count($parentnode/page) &gt; 0">
      <ul>
        <xsl:for-each select="$parentnode/page">
       
          <!--<li>
            link:-<xsl:value-of select="$currentPage"/>=<xsl:value-of select="translate(@link, $uppercase , $smallcase)"/>
           
          </li>-->
          <li >
         
            <xsl:if test="$currentPage=translate(@link, $uppercase , $smallcase)">
              <xsl:attribute name="style">color:Red</xsl:attribute>
            </xsl:if>
            <xsl:choose>
              <xsl:when test="@label=1">

                <span>
               
                  <xsl:value-of select="@caption"/>

                </span>
              </xsl:when>
              <xsl:otherwise>
                <a href="#" rel="{@rel}">

                  <!--Added by anup on 10/04/2014-->
                  <xsl:if test="@class!=''">
                    <xsl:attribute name="class">
                      <xsl:value-of select="@class"/>
                    </xsl:attribute>
                  </xsl:if>
                  <!--Added by anup on 10/04/2014-->

                  <xsl:if test="@link!=''">
                    <xsl:attribute name="href">
                      <xsl:value-of select="@link"/>
                    </xsl:attribute>
                  </xsl:if>
                  <xsl:if test="@target!=''">
                    <xsl:attribute name="target">
                      <xsl:value-of select="@target"/>
                    </xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="@caption"/>
                </a>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="number(@level) &lt;= 2">
              <xsl:call-template name="drawChildNodes">
                <xsl:with-param name="parentnode" select="."/>
              </xsl:call-template>
            </xsl:if>
          </li>
        </xsl:for-each>
      </ul>
     
     
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>