Thursday, 7 May 2015

Json call after function call

 $.ajaxSetup({
        async: false
     });

     functionname();
 
    $.ajaxSetup({
        async: true
    });

Tuesday, 20 January 2015

get data table details in SQl

SELECT COLUMN_NAME 'All_Columns',DATA_TYPE ,character_octet_length  FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Tb_TVShow'

Friday, 28 November 2014

upload excel file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.OleDb;
using System.Data;


public partial class Upload_presnews_file : System.Web.UI.Page
{
    string _strKVBDataConnString;

    public string StrKVBDataConnString
    {
        get { return _strKVBDataConnString; }
        set { _strKVBDataConnString = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

         



          
        }
        catch (Exception ex)
        {
            // lblErrMsg.Text = ex.Message.ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            try
            {
                #region variable
                string FULLNAME, ADDRESS, COUNTRY, STATE, DISTRICT, PINCOD, FOLIO_No, INVESTTYPE, NETDIV, Dividend_Year;
                //DateTime IEPFTRDATE, Date_of_Dividend;
               string IEPFTRDATE, Date_of_Dividend;
                ArrayList _event = new ArrayList();
                #endregion

                string strFolderName = Server.MapPath("iepf/");
                string strFolderPath = "";
                FileUploadiepf.SaveAs(strFolderName + FileUploadiepf.FileName);
                string strFileType = System.IO.Path.GetExtension(FileUploadiepf.FileName).ToLower();
                //        StrKVBDataConnString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                //@"Data Source=" + strFolderPath + ";" +
                //"Extended Properties=\"Text;HDR=Yes;FORMAT=Delimited\"";
                //StrKVBDataConnString = ("Provider=Microsoft.ACE.OLEDB.12.0;" +
                //  "Data Source=" + strFolderName + FileUploadiepf.FileName + ";" +
                //  "Extended Properties=Excel 12.0 Xml");


                if (strFileType.ToLower() == ".xlsx".ToLower())
                {
                    //strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filetoread + ";" + "Extended Properties=Excel 12.0;";   //Previous Code
                    StrKVBDataConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFolderName + FileUploadiepf.FileName + @";Extended Properties=" + Convert.ToChar(34).ToString() + @"Excel 12.0;Imex=1;HDR=Yes;" + Convert.ToChar(34).ToString(); //Modified Code
                }
                else
                {
                    //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filetoread + ";" + "Extended Properties=Excel 8.0;"; //Previous Code
                    StrKVBDataConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFolderName + FileUploadiepf.FileName + @";Extended Properties=" + Convert.ToChar(34).ToString() + @"Excel 8.0;Imex=1;HDR=Yes;" + Convert.ToChar(34).ToString();   //Modified Code
                    //strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filetoread + ";" + "Extended Properties=Excel 8.0;HDR=YES;";
                }

               
                //StrKVBDataConnString = ("Provider=Microsoft.ACE.OLEDB.12.0;" +
                //"Data Source=" + strFolderName + FileUploadiepf.FileName + ";" +
                //"Extended Properties=Excel 8.0 Xml; HDR=YES");
                OleDbConnection objConnection;
                OleDbDataAdapter adapter;
                objConnection = new OleDbConnection(StrKVBDataConnString);
                objConnection.Open();


                //FileUploadiepf.SaveAs( strFolderName+ FileUploadiepf.FileName);

                string strQuery = "SELECT * FROM [Sheet1$]";

                //OleDbConnection objConnection = new OleDbConnection(StrKVBDataConnString);
                //objConnection.Open();
                OleDbDataAdapter EventDataDataAdapter = new OleDbDataAdapter(strQuery, objConnection);

                DataSet EventDataDataSet = new DataSet();
                // Populate the DataSet with the spreadsheet worksheet data
                EventDataDataAdapter.Fill(EventDataDataSet);
                objConnection.Close();

                _event.Add(@"exec sp_stattv_pressnews 'delete'");

                System.Text.StringBuilder EventDataStrB = new System.Text.StringBuilder();

                EventDataStrB.Append("Declare @ID As bigint  ");
                foreach (DataRow drr in EventDataDataSet.Tables[0].Rows)
                {
                    //AMFIcode = drr["AMFIcodenew"].ToString();
                    //eventName = drr["EVENTNAME"].ToString();
                    FULLNAME = drr["FULLNAME"].ToString();
                    ADDRESS = drr["ADDRESS"].ToString();
                    COUNTRY = drr["COUNTRY"].ToString();
                    STATE = drr["STATE"].ToString();
                    DISTRICT = drr["DISTRICT"].ToString();
                    PINCOD = drr["PINCOD"].ToString();
                    FOLIO_No = drr["FOLIO No"].ToString();
                    INVESTTYPE = drr["INVESTTYPE"].ToString();
                    NETDIV = drr["NETDIV"].ToString();
                    try
                    {
                           IEPFTRDATE = Convert.ToDateTime(drr["IEPFTRDATE"]).ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    catch
                    {
                        IEPFTRDATE = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    Dividend_Year = drr["Dividend Year"].ToString();
                    try
                    {     Date_of_Dividend = Convert.ToDateTime(drr["Date of Dividend"]).ToString("yyyy/MM/dd HH:mm:ss");
                        //Date_of_Dividend = txtYear + "/" + txtMonth + "/" + txtDate +" 12:00:00 AM";
                    }
                    catch
                    {
                        Date_of_Dividend = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    }
                    //Response.Write(Date_of_Dividend + "<br/>" + IEPFTRDATE);

                    if (!string.IsNullOrEmpty(FOLIO_No))
                    {
                        _event.Add(@"exec sp_stattv_pressnews 'newsDATAInsert','" + FULLNAME + "','" + ADDRESS + "','" + COUNTRY + "','" + STATE + "','"
                            + DISTRICT + "','" + PINCOD + "','" + FOLIO_No + "','" + INVESTTYPE + "','" + NETDIV
                            + "','" + IEPFTRDATE + "','" + Dividend_Year + "','" + Date_of_Dividend + "' ");
                        //Response.Write(@"exec sp_KVB_IEPF 'IEPFDATAInsert','" + FULLNAME + "','" + ADDRESS + "','" + COUNTRY + "','" + STATE + "','"
                        //   + DISTRICT + "','" + PINCOD + "','" + FOLIO_No + "','" + INVESTTYPE + "','" + NETDIV
                        //   + "','" + IEPFTRDATE + "','" + Dividend_Year + "','" + Date_of_Dividend + "' ");
                    }

                }
                SqlHelper _sqlHelper = new SqlHelper();
                bool flag = false;
                try
                {
                     flag = SqlHelper.MultiTransaction(_sqlHelper.Connection, _event);

                }
                catch (Exception ex)
                {
                    Response.Write(ex.ToString());
                }

                if (flag)
                {
                    Response.Write("File Imported Successfully: strFileNameToImport <br/>");
                }
                else
                {
                    Response.Write("Error Occurred While Importing Data: <br/>");
                }




            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }
}

Friday, 12 September 2014

Html file call in Master page as contain placeholder -- dynamic usercontrol for all pages as per folder /page

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

public partial class Html_htmlcall : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                //------------------------find file name with folder name start code-------------

                string filename = Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath);
                string urlname = HttpContext.Current.Request.Url.AbsolutePath;
                //for my local
               //urlname = urlname.Replace("/NewRnd", "");
                //compete
                string folderpath = urlname.Replace("/" + filename, "");
                if (folderpath.StartsWith("/"))
                {
                    folderpath = folderpath.Remove(0, 1);
                }
                string[] folderlength = folderpath.Split('/');
                string newfolderpath = "";
                if (folderlength.Length > 0)
                {
                    foreach (string s in folderlength)
                    {
                        newfolderpath = newfolderpath + s + "-";
                    }
                }
                if (newfolderpath.Length == 1)
                {
                    newfolderpath = "";
                }

                //---------------------------end code-------------

                //Response.Write(newfolderpath);

                string uriFileExt = Path.GetExtension(HttpContext.Current.Request.Url.AbsolutePath);// HttpContext.Current.Request.Url.AbsoluteUri;
                string uri1 = HttpContext.Current.Request.Url.AbsoluteUri.Replace(uriFileExt, ".html");
                string pagename=Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath).Replace(uriFileExt, ".html");
                //string uri = "http://10.132.150.2:8313/thankyou.html";
                string uri = "http://" + HttpUtility.UrlDecode(HttpContext.Current.Request.ServerVariables["http_host"] + "/uploads/"+ newfolderpath+ pagename);

               // string uri = "http://" + HttpUtility.UrlDecode(HttpContext.Current.Request.ServerVariables["http_host"] + "/uploads/voting-policy.html");
                HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
                req.KeepAlive = false;
                //req.ContentLength = 0;
                //req.ContentType = "text/json";
                //Stream data = req.GetRequestStream();
                //data.Close();
                string result;
                using (WebResponse resp = req.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
                    {
                        result = reader.ReadToEnd();
                    }
                }
                htmlprindiv.InnerHtml = result;
                // rtxtResult.AppendText(htmlText);
            }
            catch (Exception ex)
            {
                //rtxtResult.AppendText(ex.Message);
            }
        }
    }
}

Monday, 25 August 2014

Server Variable for page url

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx

string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx

string host = HttpContext.Current.Request.Url.Host;
// localhost
Path.GetFileName( Request.Url.AbsolutePath )
pramod.aspx
EXAMPLE (Sample URL)
http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
HttpContext.Current.Request.Url.Host
HttpContext.Current.Request.Url.Authority
HttpContext.Current.Request.Url.AbsolutePath
HttpContext.Current.Request.ApplicationPath
HttpContext.Current.Request.Url.AbsoluteUri
HttpContext.Current.Request.Url.PathAndQuery
localhost
localhost:60527
/WebSite1test/Default2.aspx
/WebSite1test
http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
EXAMPLE (Sample URL)
http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
string url = Request.Url.Host;
localhost:2806 
"http://localhost:1234/Default.aspx?un=asdf&somethingelse=fdsa"
or like this:
"https://www.something.com/index.html?a=123&b=4567"
and you only want the part that a user would type in then this will work:
String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
String strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
which would result in these:
"http://localhost:1234/"
"https://www.something.com/"

Tuesday, 19 August 2014

Download file on html page use handler file

html code

    <a  id="downloadfile" href='pdfHandlerfile.ashx?filename=file1.pdf' target="_self" >download</a>
---------------------------------------------------------
<%@ WebHandler Language="C#" Class="pdf_Handler" %>

using System;
using System.Web;
using System.IO;
 
public class pdfHandlerfile : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
     
    if( HttpContext.Current.Request.QueryString["filename"] !=null)
        PDFdownload(HttpContext.Current.Request.QueryString["filename"].ToString());
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

    public void PDFdownload(string filename)
    {
        try
        {

            string contentType = "Application/pdf";
            HttpContext.Current.Response.ContentType = contentType;
            HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename="+filename+"");

            //Write the file directly to the HTTP content output stream.
            HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath(filename));
            HttpContext.Current.Response.End();
        }
        catch (Exception ex)
        {
        }
    }

}

Tuesday, 12 August 2014

json, jquery, JavaScript search as per first character and string autocomplete.


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="../js1/jquery-1.7.1.min.js"></script>
<script  type="text/javascript" src="../js1/jquery.ui.core.min.js"></script>
<script  type="text/javascript" src="../js1/jquery.ui.widget.min.js"></script>
<script  type="text/javascript" src="../js1/jquery.ui.position.min.js"></script>
<script  type="text/javascript" src="../js1/jquery.ui.autocomplete.min.js"></script>
    <script type="text/javascript">
        var availableTags;
        var re = "";
          var res ="";
          var res1 = "";
          var r = 0;
     
         function setval1( kk)
         {
             $("#txtHour").val(kk);
         }
           $(function () {
               var cValue = document.getElementById("hdnList").value
               var list = cValue.split(",");
               availableTags = list;
               $("#txtHour").autocomplete({
                   autoFocus: true,
                   source: availableTags,
                   multiple: true,
                   matchContains: true,
                   open: function (event, ui) {
                       //alert("hej" + availableTags);
                   }
               })
               .data("autocomplete")._renderItem = function (ul, item) {
                   res1 = item.value;
                   res = $("#txtHour").val();
                   r1 = res.length;
                   res1 = res1.substring(0, parseInt(r1));
                   res = res.substring(0, parseInt(r1));
                   if (res1 == res) {
                       return $("<li></li>").data("item.autocomplete", item)
                    .append("<a>" + item.value +  "</a>")
                    .appendTo(ul);
                       
                   }
                   return false;
               };
           });
    </script>

     <script language="javascript" type="text/javascript">
         function validateCheckBoxes(source, args) {
             var cValue = document.getElementById("hdnList").value
             var list = cValue.split(",");
             availableTags = list;
             var flag = false;
             for (var i = 0; i < list.length; i++) {
                 if (list[i].toString() == document.getElementById("txtHour").value.toString()) {
                     flag = true;
                 }
             }
             if (flag)
                 args.IsValid = true;
             else
                 args.IsValid = false;
               
         }
    </script>
</head>
<body>
    <form id="form1" runat="server">
 
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
     <asp:HiddenField ID="hdnList" Value="21:AM,2:AM,3:AM,4:AM,5:AM,6:AM,7:AM,8:AM,9:AM,10:AM,11:AM,12:AM,32:AM,22:AM,mumbai,abmumbai,ccmumbai"
        runat="server" />
                  <asp:TextBox ID="txtHour" runat="server" onblur="if (this.value == '') {this.value='Type Hour'}"
                                                            onfocus="if (this.value =='Type Hour') {this.value = ''}" MaxLength="15" Text="Type Hour" ClientIDMode="Static"></asp:TextBox>
<asp:CustomValidator id="CustomValidator1" runat="server" ErrorMessage="Not match City Name"  EnableClientScript="true"
                 ClientValidationFunction="validateCheckBoxes">
                </asp:CustomValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>  <div id="search" ></div>
    </form>
</body>
</html>