Wednesday, 28 November 2018

Download DataList checkbox checked file in zip using Ionic.zip dll in asp.net

//////////////////// HTML

 using Ionic.Zip; namespace


<asp:DataList ID="DL_FileManagement" runat="server" DataKeyField="FileNames" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="row col-lg-12"
CellPadding="2" CellSpacing="5">
   <ItemStyle ForeColor="Black" />
         <ItemTemplate>
           <div class="col-lg-2 p-0">
               <asp:CheckBox runat="server" ID="Chk_TabtoDownload" Style="float: left; margin-top: 6px; margin-right: -8px;" CssClass="pull-right" Text="&nbsp;" />

                  </div>
                       </ItemTemplate>
    </asp:DataList>


button

<asp:LinkButton runat="server" ID="lbtn_FMDataBulk" OnClick="lbtn_FMDataBulk_OnClick">
                                                     <i class="glyphicon glyphicon-download btn-success" style="font-size:15px; padding:5px;"></i>
                                                                </asp:LinkButton>




//////////////////////////////.cs



protected void Download_Files_Zip(List<string> filenames, string FolderName)
    {
        try
        {
            string fullPath = ResolveUrl("~/" + FolderName + "/");
            string chkFile = Server.MapPath("~/" + FolderName + "/");

            using (ZipFile zip = new ZipFile())
            {
                zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                zip.AddDirectoryByName("Files");
                for (int i = 0; i < filenames.Count; i++)
                {
                    string Fpaths = chkFile + Convert.ToString(filenames[i]);
                    FileInfo fi = new FileInfo(Fpaths);
                    if (fi.Exists)
                    {
                        string filePath = fullPath + Convert.ToString(filenames[i]);
                        zip.AddFile(filePath, "Files");
                    }
                }
                Response.Clear();
                Response.BufferOutput = false;
                string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyyMMMddHHmmss"));
                Response.ContentType = "application/zip";
                Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                zip.Save(Response.OutputStream);
                Response.End();
            }
        }
        catch (Exception)
        {
        }
    }

    protected void lbtn_FMDataBulk_OnClick(object sender, EventArgs e)
    {
        try
        {
            int i = 0;
            string[] files = new string[] { };
            List<string> filesNames = new List<string>();
            foreach (DataListItem item in DL_FileManagement.Items)
            {
                if ((item.FindControl("Chk_TabtoDownload") as CheckBox).Checked)
                {
                    filesNames.Add((item.FindControl("lbl_FilesNames") as Label).Text);
                    i++;
                }
            }
            Download_Files_Zip(filesNames, "Document");
        }
        catch (Exception)
        {
        }
    }


Redirect web service error to the custom error page in asp.net using Globle.asax and web.config file

////////////////////////   web.config file

  <!--<customErrors mode="On" defaultRedirect="~/Error-page"> </customErrors>-->

--------------------------------------------------
<system.web>
    <webServices>
      <protocols>
        <remove name="Documentation"/>
      </protocols>
    </webServices>
   </system.web>
--------------------------------------------------
  <system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="Redirect">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
      <remove statusCode="403" subStatusCode="-1" />
      <error statusCode="403" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
      <remove statusCode="405" subStatusCode="-1" />
      <error statusCode="405" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
    </httpErrors>
</system.webServer>



////////////////////////   web.config file


protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = Server.GetLastError();
        Response.Clear();

        HttpException httpException = exception as HttpException;

        if (httpException != null)
        {
            string action;

            switch (httpException.GetHttpCode())
            {
                case 404:
                    // page not found
                    action = "~/Error-page";
                    break;
                case 500:
                    // server error
                    action = "~/Error-page";
                    break;
                default:
                    action = "~/Error-page";
                    break;
            }

            // clear error on server
            Server.ClearError();
            Response.Redirect("~/Error-page");
        }
    }

Install windows service using command prompt

//////////////// Steps---------------


Step 1.  C:\Windows\system32>cd /

Step 2. C:\> cd \Windows\Microsoft.NET\Framework>cd v4.0.30319 (press Enter Key)

Step 3. C:\Windows\Microsoft.NET\Framework\v4.0.30319>

for uninstall

Step 4.  C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil.exe -u D:\FolderPath\WindowsService.exe

for install

Step 5.  C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil.exe -i D:\FolderPath\WindowsService.exe

                       

Friday, 16 November 2018

Increase font-size click on button using jquery

/////////// HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
    <title>increase or decrease font size of website in asp.net</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            var divtxt = $('#ChDfontdiv');
            // Increase Font Size
            $('#incrsfont').click(function () {
                GetAllSize("p");
            });
            // Decrease Font Size
            $('#decrsfont').click(function () {
                GetAllSize("m");
            })
            function GetAllSize(siz) {
                $('#ChDfontdiv div, #ChDfontdiv span, #ChDfontdiv label, #ChDfontdiv .heading').each(function () {
                    if (siz == "p") {
                        debugger;
                        var curSize = $(this).css('fontSize');
                        var newSize = parseInt(curSize.replace("px", "")) + 1;
                        $(this).css("fontSize", newSize + "px");
                        if (newSize > 12) {
                            $('#decrsfont').removeAttr("disabled");
                        }
                        if (newSize >= 25) {
                            $('#incrsfont').attr("disabled", "disabled");
                        }
                    }
                    else if (siz == "m") {
                        var curSize = $(this).css('fontSize');
                        var newSize = parseInt(curSize.replace("px", "")) - 1;
                        $(this).css("fontSize", newSize + "px");
                        if (newSize <= 12) {
                            $('#decrsfont').attr("disabled", "disabled");
                        }
                        if (newSize < 25) {
                            $('#incrsfont').removeAttr("disabled");
                        }
                    }
                });
            }
        });
    </script>
    <style>
        body{ font-size:12px;}
    .heading{ font-size:18px; font-weight:bold;}
    </style>
</head>
<body>
  
    <div id="ChDfontdiv">
    <div class="heading">
    heading heading heading
    </div>
      <div>div div div div div</div>
        <span>span span span span span</span>
        <label>label label label label label</label>
    </div>
    <br />
    <input type="button" id="incrsfont" value=" + " />
    <input type="button" id="decrsfont" value=" - " />
  
</body>
</html>







Friday, 2 November 2018

Add / Insert Identity column to DataTable in asp.net C#

////////////////////


DataTable dt = new DataTable();

        //Add columns to DataTable.
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });

        //Set AutoIncrement True for the First Column.
        dt.Columns["Id"].AutoIncrement = true;

        //Set the Starting or Seed value.
        dt.Columns["Id"].AutoIncrementSeed = 1;

        //Set the Increment value.
        dt.Columns["Id"].AutoIncrementStep = 1;

        //Add rows to DataTable.
        dt.Rows.Add(null, "Raja", "India");
        dt.Rows.Add(null, "Ram", "US");
        dt.Rows.Add(null, "Mohan", "UK");
        dt.Rows.Add(null, "Ray", "Russia");
        dt.Rows.Add(null, "Jai", "China");



Monday, 29 October 2018

Too many fields defined excel import get data

///////////////
Error

too many fields defined


Case-
The internal column count that Microsoft Access uses to track the number of fields in the table has reached 255, even though you may have fewer than 255 fields in the table. This can happen because Access does not change the internal column count when you delete a field. Access also creates a new field (increasing the internal column count by 1) for every field whose properties you modify.

////////////Solution

Where////////////// A1:R51 Sheet range , selected by columns

using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM Shee$A1:R51]", excel_con))
{
  oda.Fill(dt);

 }

copy excel sheet name to cell

///////////////////


Select a blank cell, copy and paste the formula =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)


How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...