Tuesday, July 29, 2025

Nupkg extension file from nuget package

 Convert nupkg file to zip file and you will get dll files in it. 


On the right hand side of nuget website you will get "download package" option.

Monday, July 28, 2025

How to print a print statement of sql in asp.net c# - how to call a another event in asp.net event

 using System;

using System.Data.SqlClient;


public class SqlPrintExample

{

    public static void Main(string[] args)

    {

        string connectionString = "Data Source=YourServer;Initial Catalog=YourDatabase;Integrated Security=True";

        string sqlQuery = "PRINT 'This message comes from SQL.'; SELECT GETDATE() AS CurrentDateTime;";


        using (SqlConnection connection = new SqlConnection(connectionString))

        {

            // Attach an event handler to capture InfoMessage events (including PRINT statements)

            connection.InfoMessage += Connection_InfoMessage;

or// conn.InfoMessage += new SqlInfoMessageEventHandler( Connection_InfoMessage);

            try

            {

                connection.Open();

                using (SqlCommand command = new SqlCommand(sqlQuery, connection))

                {

                    using (SqlDataReader reader = command.ExecuteReader())

                    {

                        while (reader.Read())

                        {

                            Console.WriteLine($"Current Date Time from SQL: {reader["CurrentDateTime"]}");

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine($"Error: {ex.Message}");

            }

        }

    }


    private static void Connection_InfoMessage(object sender, SqlInfoMessageEventArgs e)

    {

        // Display the message from the SQL PRINT statement

        Console.WriteLine($"SQL InfoMessage: {e.Message}");

    }

}

do while loop in sql server - Cursor in Sql Server

For data looping in sql Server, we use While loop  or cursor


 DECLARE @cnt INT = 0;


WHILE @cnt < 10

BEGIN

   PRINT 'Inside simulated FOR LOOP on TechOnTheNet.com';

   SET @cnt = @cnt + 1;

END;


PRINT 'Done simulated FOR LOOP on TechOnTheNet.com';

GO


For cursor:-


https://www.c-sharpcorner.com/blogs/how-to-use-cursors-and-while-loop-in-sql-server

Thursday, July 17, 2025

How to download the file secretly using webclient class -asp.net c#

  using (WebClient client = new WebClient())

        {

            


            string url = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOJA1ZDa4CQ6OwLx-iL10cLEXpzoJZmZUVLHjJqHBr3-Q9TBEBpjD_ZZgtNGMj59CXGWtZ1yu-CfUoyuU8I7nGjgpwk0wCal_oGSPZNREQssIHeC5PFC10v8YdEIe5ie2wLyfGsrHSBR213ATgNXPyotNs66AoYF2CWPfAx9gu2cgYKw/s1600/Screenshot%202025-05-14%20184428.png";

            

            string savePath = "D:/image1212.jpg";

            client.DownloadFile(url, savePath);


        }


How to call a http handler in web form - asp.net c#

 <script type="text/javascript" src="http://localhost:49183/AsyncHTTPModuleHandler/MyHandler.ashx?url=<%= Request.Path%>">

</script>


public override ProcessRequestAsync(HttpContext context)
{

    string targetUrl = context.Request.QueryString["url"];
}

Thursday, July 10, 2025

How to create and download txt file programaticaly with asp.net c# and write content in it

   Response.Clear();

        Response.Write("This is an HttpHandler Test.");

        Response.Write("<p>Your Browser:</p>");


        Response.AddHeader("content-disposition", "attachment; filename=t.txt");

        Response.End(); 

How to download pdf file from server not on database only on server - Simplest way

//only two lines code is required that is uncommented

//Response.Clear(); // This is i am not using because response.clear is used for clearing http response (like text) but this is a file that is presently on server. Also when we create pdf of text file than we use clear function and we are getting pdf file from database (binary fromat) Response.buffer is default true so we don't need.

 Response.AddHeader("content-disposition", "attachment; filename=t.pdf"); 

 //Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf; 

        //"application/octet-stream"; 

        Response.WriteFile(Server.MapPath("~/App_Data/Annexure.pdf")); // File must be there on server otherwise it will give error


//Response.end is also we are not using because we are not creating pdf file , if we create pdf file or we are getting from database than we use Response.End and Response.Clear() functions.

Response.WriteFile or Response.TransmitFile use in asp.net c# - how to view pdf or text file in web browser

 It is used to show the content of any file in web browser.  This  is same as response.write but it will write the content of the file to web page. Mainly it is used to view the file content not to download the file.  Both Response.WriteFile or Response.TransmitFile  are same

example if text file than use code below

For PDF file

Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;

Response.WriteFile(Server.MapPath("~/App_Data/Annexure.pdf"));


For txt file

Response.Clear(); 

     

        Response.ContentType = System.Net.Mime.MediaTypeNames.Text.Plain;  and use Text.html

        //"application/octet-stream"; 

        Response.WriteFile(Server.MapPath("~/App_Data/yash.txt"));

        Response.End(); 



or on page load, simply we can show the content of text file

Response.WriteFile("~/App_Data/" + fileName);