Thursday, 23 June 2011

Forcefully excel file generates in .net

//MicroSoft.Office.Interop.Excel (import this as references)
        string filename = "";
        private void CreateExcelSheet()
        {
            try
            {
                //-----------------------------------------------
                DataTable dtExcelImport = new DataTable();
                dtExcelImport = clsApp.getDataTable("select * from student");
                Microsoft.Office.Interop.Excel.Application oXL;
                Microsoft.Office.Interop.Excel._Workbook oWB;
                Microsoft.Office.Interop.Excel._Worksheet oSheet;
                oXL = new Microsoft.Office.Interop.Excel.Application();
                oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value)); //----- to create new xls
                //oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Server.MapPath("PreFormated.xls"))); //--- use existing xls
                oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;
                string rg = "A1:";
                Microsoft.Office.Interop.Excel.Range range1;
                if (dtExcelImport.Rows.Count > 0)
                {
                    oSheet.Cells[1, 1] = dtExcelImport.Rows[0]["column-1"].ToString();
                    oSheet.Cells[1, 2] = dtExcelImport.Rows[0]["column-2"].ToString();
                    oSheet.Cells[1, 3] = dtExcelImport.Rows[0]["column-3"].ToString();
                    oSheet.Cells[1, 4] = dtExcelImport.Rows[0]["column-4"].ToString();
                    oSheet.Cells[1, 5] = dtExcelImport.Rows[0]["column-5"].ToString();
                }
                oSheet = null;
                range1 = null;
                //========= accessPath to specific folder =======
                filename = DateTime.Now.ToString("dd/MMM/yyyy") + ".xls";
                filename = Server.MapPath("~/myFolder/" + filename);
                //========= Access bin folder =======
                //filename = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                //filename = filename.Replace(@"file:\", "");
                //filename += "\\myFile" + ".xls"; 
                //=========================
                oWB.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                    Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                oWB.Close(Missing.Value, Missing.Value, Missing.Value);
                oWB = null;
                oXL.Quit();
            }
            catch (Exception ex)
            {
            }
        }

How to use progress bar in page centre using JQuery in ASP.Net Ajax ?

//---- Direct copy - paste this code 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.CS.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Modal Popup Window</title>

    <script type="text/javascript" language="javascript">
        var ModalProgress = '<%= ModalProgress.ClientID %>';     
    </script>

    <style type="text/css">
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=50);
            opacity: 0.50;
        }
        .updateProgress
        {
            border-width: 1px;
            border-style: solid;
            background-color: #FFFFFF;
            position: absolute;
            width: 180px;
            height: 65px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <script type="text/javascript">
            //---- Note : This script don't define in header tag of the page.
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endReq);

            function beginReq(sender, args) {               
                $find(ModalProgress).show();// shows the Popup
            }
            function endReq(sender, args) {               
                $find(ModalProgress).hide();//  shows the Popup
            }      
        </script>

        <asp:ScriptManager ID="ScriptManager1" runat="server" />
       
        <asp:Panel ID="panelUpdateProgress" runat="server" CssClass="updateProgress">
            <asp:UpdateProgress ID="UpdateProg1" DisplayAfter="0" runat="server">
                <ProgressTemplate>
                    <div style="position: relative; top: 30%; text-align: center;">
                        <img src="loading.gif" style="vertical-align: middle" alt="Processing" />                       
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </asp:Panel>
       
        <ajaxToolkit:ModalPopupExtender ID="ModalProgress" runat="server" TargetControlID="panelUpdateProgress"
            BackgroundCssClass="modalBackground" PopupControlID="panelUpdateProgress" />
           
        <asp:UpdatePanel ID="updatePanel" runat="server">
            <ContentTemplate>
                <asp:Button runat="server" Text="Click Me" ID="btnSubmit" OnClick="btnSubmit_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
       
    </div>
    </form>
</body>
</html>


//------------------- cs code ----------------------------------

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(4000);
       //------  if you want to dynamically call (Model Popup) then comment above line please.
    }



Wednesday, 22 June 2011

Managed and Unmanaged code

Managed Code :
A code that executed and understandable the instructions of CLR is called Managed code. Typically applications written in Java, VB.Net, C#.Net etc.
Code that is executed by the CLR and provides information - store, retrieve security information, handle exceptions, encoded in assembly modules, garbase collection etc.
Unmanaged Code :
A code that execute without the instruction of CLR is called Un-managed code.
Code that is directly executed by the operating system is known as Unmanaged code. Typically applications written in VB6.0, C, C++ etc all are examples of Unmanaged code.
Unmanaged code is always compiled to the native code which is architecture specific. when we compile unmanaged code it gets compiled into a binary x86 image. and this image always depends on the platform on which the code was compiled and can not the executed on the other platforms.
In unmanaged code the memory management, type safety, security etc needs to be taken care of by the developers.



What is differenct between Null and Blank ?

1. A null value represents the absence of a value for a record in a field.
2. Null isn't allocated any memory, Blank is allocated to a memory location,
    although the value stored in the memory is "" .
3. Null has no bounds, it can be used for string, integer, date etc.
    but empty string is just regarding a string. it's a string like : 'Computer'.

What is smart navigation in .Net ?

The cursor position is maintained when the page get refreshed due to the server side validation and the page gets refreshed.

Difference between sql server 2000, 2005, 2008

2000 2005 2008
Query Analyser and Enterprise manager
Both are separate. Both are combined (SSMS). ------
XML datatype is used.  
No XML datatype XML datatype is introduced ------
maximum databases.

max 65,535 databases. max 2(pow(20))-1 databases ------
Exception Handling

Nill Exception Handling ------
Varchar(Max) data type
Nill Varchar(Max) data type ------
DDL Triggers

Nill DDL Triggers ------
DataBase Mirroring

Nill DataBase Mirroring ------
RowNumber function for paging
Nill RowNumber function for paging ------
Table fragmentation

Nill Table fragmentation ------
Full Text Search

Nill Full Text Search ------
Bulk Copy Update

Nill Bulk Copy Update ------
Encrypt

Nill Nill introduced in 2008.
Compress tables and indexes
Nill Introduced in 2005 SP2 ------
Datetime  
used for both(date-time). Nill seperately used for(date & time datatype)
table datatype
 
Nill Nill Table datatype introduced.
SSIS 
 
Nill SSIS is started using. ------
CMS (Central Management Server)
Nill Nill CMS Introduced.
PBM (Policy based management)
Nill Nill PBM server is Introduced.