Tuesday, May 31, 2022

Export to excel from sql database SQL Query in ASP.NET C#

 protected void imgexcel_Click(object sender, ImageClickEventArgs e)

    {

          string strQuery = (" EXEC Spu_Get_InvoiceStatus ");

        SqlCommand cmd = new SqlCommand(strQuery);


        DataTable dt = GetData(cmd);


        //dt.Columns.Remove("I_PMU_EntryOn");

        dt.Columns.Remove("yearofBSD");

        dt.Columns.Remove("TP_State_Code");

      

        dt.AcceptChanges();

        GridView GridView1 = new GridView();

How to remove href link when printing of page CTRL+P (CSS)

 When printing of page (Pressing CTRL+P), if you want to remove href links(hyper links)

Use below code:-

@media Print

         {

             a[href]:after

             {

                 content: none !important;

             }

         }

Update Panel ASP.NET C# loading.gif masking css



 If we have master page in asp.net, use below code:-

 <style type="text/css">

 .divWaiting {

position: absolute;

background-color: #FAFAFA;

z-index: 2147483647 !important;

opacity: 0.8;

overflow: hidden;

text-align: center;

top: 0;

left: 0;

height: 100%;

width: 100%;

padding-top:20%;

}

</style>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">

    </asp:ScriptManager>

<asp:UpdatePanel ID="UpdGrid" runat="server" UpdateMode="Always">

            <ContentTemplate>

                <asp:UpdateProgress ID="updprogress" runat="server" DisplayAfter="0"  AssociatedUpdatePanelID="UpdGrid">

       <ProgressTemplate>

        <div class="divWaiting">

            <asp:Label ID="lblWait" runat="server" 

Text=" Please wait... " />

            <asp:Image ID="imgWait" runat="server" ImageUrl="~/loading.gif"    />

          </div>

       </ProgressTemplate>

       </asp:UpdateProgress>

 </ContentTemplate>

        </asp:UpdatePanel>

</asp:Content>


---------------

Note:- If this is not working properly than Change  .divWaiting {

position: absolute; } to position: fixed; 

Update Panel with Grid View With progress bar ASP.NET C#

<asp:UpdatePanel ID="UpdGrid" runat="server" UpdateMode="Always">

            <ContentTemplate>

                <asp:UpdateProgress ID="updprogress" runat="server" DisplayAfter="0"  AssociatedUpdatePanelID="UpdGrid">

       <ProgressTemplate>

       <label>Please Wait...............</label>

       </ProgressTemplate>

       </asp:UpdateProgress>


 <asp:GridView ID="GridInvoice" runat="server" GridLines="None" AllowPaging="false">


</asp:GridView>


</ContentTemplate>

        </asp:UpdatePanel>

How to insert records in array from data rows

 List<string> batch=new List<string>();

if(dt.Rows.Count >0)

{

    for(int i=0; i<dt.Rows.Count; i++)

    {

        batch.Add(dt.Rows[i].["BatchCode"].toString());//this is from database

    }

}


Microsoft classes code files

 github.com/microsoft

How to register dll file in windows 10

 >Open command prompt

> write regsvr32 test.dll

ASP.NET C# SQL queries in APP_GlobalResouces

 > Create App_GlobalResources folder

> Right click on App_GlobalResources folder and Add Resource file

> Create CommonQuery.resx

> Add (name = ErrorMessage, value = Error Occured and comment= test)

> Use Resources.CommonQuery.ErrorMessage in any .cs page.

How to clear activity history in windows 10

 > Click on start button and type 

> Clear activity history or on taskbar click task view icon

> and click on clear


Condition in ASP.NET C# if URL is having ? in if condition

 if(Request.Url.AbsoluteUri.ToString().IndexOf("?")>0)

{

//Your condition here

}

How to disable or enable copy paste cut disable in Textbox

Change the properties - For disable

 Oncopy="return false"

 Onpaste="return false"

 Oncut="return false"

-------------

Change the properties - For enable

 Oncopy="return true"

 Onpaste="return true"

 Oncut="return true"

Steps recording in window 10

 >Press start button

> Click on windows accesseries 

> Click on steps recorder 

Windows 10 Updates

 >Click on start button

> Click on Settings

> Click on Updates and Security

How to delete or disable breakpoint in Visual studio

>Open Visual studio

> Click on Debug menu

> Click on delete all breakpoints or disable all breakpoints

How to stop VB Script in windows 10, if it is not stopping (auto running)


 Click on Task Manager and stop process below:-

> wscript.exe

>cscript.exe

---------------------------------------

For example, if you want to stop file test.vbs with below code that is running automatically

set ws = CreateObject("wscript.shell")

do wscript.sleep 3000

ws.sendkeys "{F5}"

loop

Monday, May 30, 2022

English stories

 Last night some hollygons torched a shanty with flambeu and fume along with scream started coming out of it. Later in the morning potency recoverd corps from it and most of the belonging turned into enders. Police have cardoned the area and have asked riffroff not to chide any one for this havoc.


I saw my duck diamond standing by the frontage of her house. I love her sorely but her father is surely. He is ambivalent by nature. I can apply any feet to draw her attention because she is the hotbed of my happiness. Her mother has orthodox thinking but she is innouces. Her brother is invisible and one day will valloop him because he is tensive. It is god verdict that she lives in the neche of my heart. When I see her, i get solace. I have bolavoured of lover for her.


I hail from a Jonty State. At present my hands are full and I am aspiring to have a go at PCS exam. I am not having having kittens about my exam though it is a herculean task. In a nutshell whether it is a hit or miss I will improve on my audacity.


How to clear history and temporary files in Windows 10 and some other commands (System fast and clean up)

 >Click window + run

>Write %temp% and press enter

>write temp, prefetch 

and some other commands :- ncpa.cpl, services.msc


---------------------------


You can also use system cleanup and defregmentation


---------------------


System is also slow due to windows update, you can see by clicking on window button> Settings> Windows update> Click on Pause update for 7 days.


Edit feature in Grid View ASP.NET C#

Use selected index change in Grid view:-


 grdCourseMaster_SelectedIndexChanged

Friday, May 27, 2022

How to create login audit and save it to database

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Text;

using System.IO;

using System.Text.RegularExpressions;

using System.Web.UI.HtmlControls;


public partial class View_TrainingPartner_ManageInvoice_InvoiceInbox : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

    {

 try

                    {

                        BLL_LoginAudit objAudit = new BLL_LoginAudit();

                        objAudit.Transction(new BO_LoginAuditMaster

                        {

                            Login_action = "I",

                            Login_Action_Type = "Invoice Inbox Page",

                            Login_Audit_id = 0,

                            Login_Date_Time = DateTime.Now,

                            Login_IP_Address = LuminiousUtility.Util.Utility.VisitorIPAddress(),

                            Login_Module_Name = "Training Partner",

                            Login_Section_Name = LuminiousUtility.Util.Utility.BrowserDetection(),

Clicking on button, restriction of moving from one page to another ScriptManager alert message

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Text;

using System.IO;

using System.Text.RegularExpressions;

using System.Web.UI.HtmlControls;

public partial class View_TrainingPartner_ManageInvoice_InvoiceInbox : System.Web.UI.Page

{

 protected void Page_Load(object sender, EventArgs e)

    {

 if (PANStatus == 0)

                {

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Please update your PAN No. before Invoice creation');", true);


                    #region redirectbtmeta

                    HtmlMeta meta = new HtmlMeta();


                    meta.HttpEquiv = "Refresh";

                    meta.Content = "1;url=../ManageCourses/TrainingPartnerProfileUpdate.aspx";


                    this.Page.Controls.Add(meta);

                    #endregion


try{}

catch{}


}
else
{
try
{}
catch{}
Response.Redirect("~/Login.aspx?errormessage=No valid session found", false);
}

}

}

Fake paging in ASP.NET C# Grid

ASPX file code

-------------------

 <asp:GridView ID="grdCourseDetails" runat="server"  CssClass="table table-responsive"

                     AutoGenerateColumns="False" 

                    EmptyDataText="No Records Found!" ShowHeaderWhenEmpty="True" 

                        AllowPaging="True"  PagerSettings-PageButtonCount="10" PagerSettings-Mode="Numeric"

                        PageSize="10"  CellPadding="4" onpageindexchanging="grdCourseDetails_PageIndexChanging"

                        ForeColor="#333333" GridLines="None" Width="100%">


                <Columns>

Introduction to e office

https://sonipat.gov.in/e-office/ 


https://youtu.be/YnJQTRzSPqY

Creating Custom errors in web.config ASP.NET C# (error page in asp.net)

 Add the below section in web.config:-

<system.web>
<customErrors mode="On" defaultRedirect="Error501.aspx">
      <error redirect="Error404.aspx" statusCode="404" />
      <error redirect="Error501.aspx" statusCode="400" />
      <error redirect="Error402.aspx" statusCode="402" />
      <error redirect="Error501.aspx" statusCode="500" />
      <error redirect="Error501.aspx" statusCode="501" />
    </customErrors>
</system.web>


Tuesday, May 24, 2022

Android Double tap to walk(Display on) or (Display off)off android phone

 >Go to settings

> Go to more settings

> Go to Smart controls

> Click on "smart wake" and "Double tap to turn off screen"

> And there are many other options on smart motion in this smart controls.

Creating New User or Guest User or Multiple User in Android phone

 > Tap phone from upper side and click on users

> Or Click on settings and click on More settings

> Click on multiple users and tap on OFF/ON button

Friday, May 20, 2022

XSD File in C#

 https://www.c-sharpcorner.com/UploadFile/deveshomar/creating-xsd-of-a-xml-using-visual-studio/

LINQ to SQL ASP.NET C# from database without writing code like Entity Framework

Business Logic Layer


 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Data.Linq;

using System.Reflection;

using System.Data.Linq.Mapping;

using System.Data.Linq.Provider;

using System.Data.Linq.SqlClient;



/// <summary>

/// Summary description for BLL_Feedback

/// </summary>

public partial class FeedBackDataContext : System.Data.Linq.DataContext

{

Tuesday, May 17, 2022

Logout button functionality in ASP.NET C#

 protected void Btn_logout_OnClick(object sender, EventArgs e)

    {

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));

        Response.Cache.SetNoStore();


        Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1d);

        Response.Expires = -1500;

        Response.CacheControl = "no-cache";

        Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);


        System.Web.Security.FormsAuthentication.SignOut();

        if (Session["ID"] != null)

        {

            Session.Remove("ID");

        }

        if (Request.Cookies["trainingartnerCookies"] != null)

        {

            Request.Cookies["trainingartnerCookies"].Expires = DateTime.Now.AddDays(-1);

            new Cookies().RemoveCookies("trainingartnerCookies");

        }

        Session.Abandon();

        Session.RemoveAll();


        Response.Redirect("Login.aspx");


    }


or in simple


we can also use below code

Session.Abandon();

Response.Redirect("login.aspx");}

Webservice returning JSON values in C# ASP.NET

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Data;

using System.Collections;

using System.Web.Script.Serialization;

/// <summary>

/// Summary description for MIETY_SkillDevelopment

/// </summary>

[WebService(Namespace = "/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

 [System.Web.Script.Services.ScriptService]

Getting file path in C# ASP.NET

  private string keyPath = "../SkillDevelopment/Key_37_10001_20191104.key";


tring fl1 = HttpContext.Current.Server.MapPath(keyPath);

Converting JSON to DataTable or Convert table to list in C# ASP.NET

 public DataSet ConvertJsonToDatatable(string jsonString)

    {

        DataSet ds = new DataSet();

        DataTable dt = new DataTable("Dash");

        ds.Tables.Add(dt);

        string s = "{" + "\"" + "RetDMDashCaption" + "\"" + ":";

        jsonString = jsonString.Replace(s, "").Trim('}');

        string[] jsonParts = Regex.Split(jsonString.Replace("[", "").Replace("]", ""), "},{");

        List<string> dtColumns = new List<string>();

GET and PUSH operation in ASP.NET C# with API and return JSON or XML

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using Luminious.Connection;

using Luminious.DataAcessLayer;

using System.Data.SqlClient;

using System.IO;

using System.Web.Script.Serialization;

using System.Collections;

using System.Text.RegularExpressions;

using System.Net;

using System.Text;

using System.Net.Http;

using System.Net.Http.Headers;

using System.Security.Cryptography;


public partial class Skilldevelopment_Details : System.Web.UI.Page

{

    //CSComClass cc = new CSComClass();

    //CSUtility fcs = new CSUtility();


    DataSet ds;

    Hashtable param;

Thursday, May 12, 2022

SQL Server sa login if not working

 ALTER LOGIN sa ENABLE ;

GO ALTER LOGIN sa WITH PASSWORD = 'FossTechnix@123'; GO


>Also you have to Open Sql server management studio
>right click on server and click on properties
>Click on security
>Click on (SQL server and windows authentication mode) and click on OK
(Please see below screenshot)
And restart sql services







Wednesday, May 11, 2022

SQL Server Scope Identity

 USE AdventureWorks2012;

GO INSERT INTO Person.ContactType ([Name]) VALUES ('Assistant to the Manager'); GO SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]; GO SELECT @@IDENTITY AS [@@IDENTITY]; GO

SQL server CASE clause when then condition

case 

    when Max_student_allowed > Original_Stu_count     THEN 'A' 

    ELSE 'NA' 

END as RegisterStudent_Status

--------------------

case 

    when Max_student_allowed > Original_Stu_count     THEN 'A' 

    ELSE ' ' 

END as RegisterStudent_Status

reference:-https://www.w3schools.com/sql/sql_case.asp


Friday, May 6, 2022

How to publish a website in ASP.NET C#

 > Open your project in Visual Studio

> Right Click on Project and click on Publish Website.(below is screenshot)



> A folder will created after clicking on publish website.

> Also click on settings while publishing in file publish options (Check all the options - Delete all existing , precompile during publication, exclude file from app_data folder)

> Now bin folder DLL files and aspx files will be created. Use that files for deployment.

String Null or Empty or int? and double?

 ? will not apply on string. It will be only apply on int?


int? a = 5;

Thursday, May 5, 2022

Refresh in windows 10 with vb script

 Create refresh.vbs file

Paste the below code:-

Set ws = CreateObject("wscript.shell")

    ws.sendkeys "{F5}"


How to create tree batch file fregmentation in windows 10

 Create tree.bat file.

paste the below text:-


"Echo off


cd/


tree


C:


tree


D:


tree"

Monday, May 2, 2022

File download docx OR XML file in ASP.NET C#

 protected void lnkDownloadAnnexB_Click(object sender, EventArgs e)

    {

        try

        {

            Response.ContentType = "application/docx";


            string filePath = "~/Document/Download/ANNEXURE-B.docx";


            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");

            Response.TransmitFile(Server.MapPath(filePath));

            Response.End();

        }

How to create dashboard in ASP.NET C#

 aspx file page


<%@ Page Title="" Language="C#" MasterPageFile="~/View/Admin/Admin.master" AutoEventWireup="true" CodeFile="Dashboard.aspx.cs" Inherits="View_Admin_Default" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<script type="text/javascript">

    $(function () {

        $('#container').highcharts({

            chart: {

                plotBackgroundColor:null,

                plotBorderWidth: 1,

                plotShadow: false

            },