Generate PDF, screenshot of a webpage in c# using phantomjs

In this post i will explain how to capture screenshot and how to create PDF of a webpage using Phantomjs.

Merging multiple PDFs using iTextSharp in asp.net c#

In this article i will show you how to merge multiple pdfs into one using ITextSharp below is the two approach one is to pass your input files path, output file path (will be created if not exist) and another is pass direct input stream, output stream and it will write the merge files into output stream.

image resizing in asp.net c# dynamically

https://www.amazon.in/Timex-Analog-Brown-Womens-Watch-TW000J106/dp/B01N65OL6T/ref=as_li_ss_tl?_encoding=UTF8&ref_=cm_sw_r_wa_apa_mXNMyb5RXPJJD&linkCode=ll1&tag=dotnetbull-21&linkId=233c25f614586702a9063bc37cbb576d

https://www.amazon.in/Casio-Enticer-Analog-Black-Womens/dp/B007V322BE/ref=as_li_ss_tl?_encoding=UTF8&ref_=cm_sw_r_wa_apa_UZNMybP5MY3HN&linkCode=ll1&tag=dotnetbull-21&linkId=e81e17c8b6cd62f02ed92809511913c7

In this article you can find the code that is for re-sizing images with given width and height and retain the quality of the image as it was.

below is the function just pass new width, new height and original image file path it will save resize given image and save it into the folder named newsizeimages and returns the new path.

Resize Image Code C#

public string CreateThumbnail(int maxWidth, int maxHeight, string path)
{

    var image = System.Drawing.Image.FromFile(path);
    var ratioX = (double)maxWidth / image.Width;
    var ratioY = (double)maxHeight / image.Height;
    var ratio = Math.Min(ratioX, ratioY);
    var newWidth = (int)(image.Width * ratio);
    var newHeight = (int)(image.Height * ratio);
    var newImage = new Bitmap(newWidth, newHeight);
    Graphics thumbGraph = Graphics.FromImage(newImage);

    thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
    thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
    //thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

    thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight);
    image.Dispose();

    string fileRelativePath = "newsizeimages/" + maxWidth + Path.GetFileName(path);
    newImage.Save(Server.MapPath(fileRelativePath), newImage.RawFormat);
    return fileRelativePath;

}

In asp.net if you want to resize client uploaded image files directly when client uploading their image files then you have to save this files first into the server and then pass this file path into the above function as given below example.
if (updImage.HasFile)
{
  try
  {
   updImage.SaveAs(Server.MapPath("uploadedimage/" + updImage.FileName));

   imgCustomTo8.ImageUrl = CreateThumbnail(8, 8, Server.MapPath("uploadedimage/" + updImage.FileName));
   imgCustomTo16.ImageUrl = CreateThumbnail(16, 16, Server.MapPath("uploadedimage/" + updImage.FileName));
   imgCustomTo24.ImageUrl = CreateThumbnail(24, 24, Server.MapPath("uploadedimage/" + updImage.FileName));
   imgCustomTo32.ImageUrl = CreateThumbnail(32, 32, Server.MapPath("uploadedimage/" + updImage.FileName));
  }
  catch
  {
           
  }

}


Download image re-sizing sample code click here.

asp.net charting controls microsoft (ms chart) Line chart samples / tutorial

If you are thinking of charting, graph and reporting then MS Chart is one of the best and easy way to display your data.
By default ms chart include with visual studio 2010 and 2012 (.net framework 4.0, 4.5 or later), you can also use it with visual studio 2008 by installing ms chart component from Microsoft website.

what is access modifier in c#

Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, member function, member variables etc. Access modifiers are a specific part of programming language syntax used to facilitate the encapsulation of components, It defines the accessibility of the specific type (e.g class, struct), data member etc.

How to maintain dynamic control events, data during postback in asp.net

In asp.net if you add some dynamic control (button, linkbutton, textbox, checkbox etc) according to some condition and want to retain data, handle their event during postback then you should aware about asp.net server control life cycle.

Find max top 5 number from three given sorted array

If you have three integer type of sorted array and want to get highest top 5 number from given these three arrays then this article is for you, here is the most efficient way of getting top 5 number from three sorted array.

Program to reverse an array with given no of elements and remains as same

In this article we will see how to reverse an array with given on of elements for the starting and remaining elements as its same position, suppose we have given this array {1,2,3,4,5,6,7,8} and number of elements to be reverse is 4 then output should be {4,3,2,1,5,6,7,8}.

What is 301 permanent and 302 temporary http status code redirection and how to implement it in asp.net c#

This article explains what is the http status code 301 and 302, 301 status code vs 302 status code, how to use it and how to implement it in your asp.net c# website.

How to get server, iis information like server ip, port , os, iis version, machine name etc in asp.net c#

This article is for retrieving all major information of hosting server and iis server like server ip address, operating system version, iis version, server computer name (machine name), current user, domain name, current executing file path, port number in which application is running etc.

binding dropdownlist in .net mvc razor by viewbag, model and jquery - 3 ways

There is a lot of ways to bind dropdownlist in asp.net mvc (mvc3, mvc4 or later razor syntax .cshtml) and maintaining dropdownlist state during postback some of them given below -
  • Use viewbag property.
  • Through view model.
  • Use jquery .ajax i.e. asynchronous post back at selected index change of another dropdownlist.

how $document.ready() is different from window.onload()

we often use window.onload() in javascript and $document.ready() in jquery and assume that both are same just jquery library wrap up javascript window.onload() and introduce $document.ready() but no there is much difference between them below is the explanation -

program to find first non repeating character in a string c# - 3 ways

In c# you want to create logic that if a string like "abcabd" is passed to a method then it should return first non repetitive character from string like in above it should return "c".

Below is three way to get the first non-repeating(distinct) character from the string -

program to removing duplicate entries, records from Array in C#.NET

Below are the four method for removing duplicate entries from an array, all does same task with the different - 2 ways using list contain (internally using linq) method, collection distinct extension method (internally using linq need .net 3.5 framework or greater) and traditional for loop also work in lower version of .net framework.

parsererror after jquery.ajax request with jsonp content type

When we make a cross domain call through jquery $.ajax method through jsonp request then often this error occurs 'jQuery1510993527567155793_137593181353 was not called parsererror' function name can vary as it is randomly generated by jquery.

httperrors vs customerrors in webconfig , iis, asp.net

Errors section in web config is for providing custom http error handling approach there are two section, one customErrors inside the section system.web and another httpErrors inside the section system.webServer (as given below)

There is much confusion between custom error and http error sections that IIS pick up setting from which section customErrors section or from httpErrors section, below are the explanation.

program for factorial using recursion, while and for loop in c#

In this article you can see how to calculate factorial of a number using recursive function , while loop and from for loop below are the three function just pass number that you want to calculate factorial and it will return the output (i.e factorial of the number).

reading multivalued cookies in javascript

Below is the three example that read cookies through javascript all of the code is for different-different purpose first of them read singlevalued and multivalued cookies just by passing name of the cookies, second one is for reading by multivalued cookies by key name just by passing cookies name and key name it returns the value of that particular key and third one is for search key name in all of the cookies present in website no matter what is the name of cookies it returns first matched value of that particular key.

Window Service For Monitor multiple folders using FileSystemWatcher

Dotnet has a class named FileSystemWatcher that is for having watch in a particular folder and sub folder (conditional), when a file created, modified, deleted or renamed , it fires respective event where we can implement our logic to prevent suspicious activity.

Multiple marker with labels in google map

In this article you will see how to add multiple marker with label in google map (marker with label text), you can write your custom marker label text or use inbuilt A-Z marker icon , custom marker css and info window that will display on clicking marker.

Below is the two method that will add multiple marker in google map.

How to post tweet on behalf of an user from asp.net using oauth authentication

In this article i am going to explain how to post tweet on behalf of an user to twitter programmatically from asp.net through oauth authentication, you just need twitter access token and token secret that i have already explain in  my previous post how to get access token, token secret and screen name.

Login with twitter using oauth authentication in asp.net and get access token, screen name and userid

Today i am going to explain how to make login with twitter functionally and get access token, access secret token key, screen name and user id of user that can be further use for post on behalf of user to twitter , getting the profile image of user, user information ,user status ,tweets and much more.

Recentaly I have posted Scrollable Gridview with fixed headers in asp.netPopulate custom pagination for databind controls using custom paging in asp.net c#Get youtube video thumbnail image of youtube video in asp.net

Copy to clipboard in javascript with zeroclipboard flash for all browser.

This article describe you how to copy text from webpage in button click using javascript or using flash that works on all major browser.

Check out these excellent article too how to select all div text in single click in JavaScripthow to highlighting text inside div in JavaScriptFinding, convert text input into hyperlink in JavaScript

below is three code sample two of them works only on Internet Explorer (Prompt may be display as per your browser security policy i.e. allow website to access your clipboard.)  and another one works in all major browser that using flash for copy to clipboard functionality.

Resize iframe inside itself to fit content, to given height from jquery and javascript

This article will show you how to resize iframe from itself to a given height or automatic fit to its content height.

Recently i have added Custom paging in asp.net using stored procedure in gridviewload more content when browser scroll to end of page in jqueryJquery scroll window to top bottom and absolute functionality and how to call a webservice from jquery articles.

Concept is very simple find iframe (i.e current working window iframe) in its parent window, find the actual content height of current working window (i.e. iframe)  and set the height (i.e css style height) to the founded iframe.

How to handle click event of linkbutton inside gridview

Recently I have posted how to sort only current page of gridview, Scrollble gridview with fixed header through javascript, File upload control inside gridview during postback and now i am going to explain how to handle click event of linkbutton or any button type control inside gridview.

We can handle click event of any button type control inside gridview by two way first is through event bubbling and second one is directly (in this type of event handling we need to access current girdviewrow container)

Custom paging in asp.net using stored procedure in gridview

When we need to display only some of the record in page and table in database contains lacks of rows then   we should have to use custom paging instead of default paging.

Why to avoid default paging and use custom paging reason -

  •  In default paging we are fetching all rows in database that takes more execution time (i.e query    execution time in SQL Server or any database management system).
  •   In default paging all rows (records of table) load in memory so memory consumption
  •   In default paging all rows fetch form back end to front end but we are displaying only some of the rows i.e page-size.

load more content when browser scroll to end of page in jquery

Recently I have posted how to make animated scrolling to top, scrolling to bottom or scrolling to a control functionality through jquery.

This article explains how to call a function on window scroll event when scroll bars reached to end of the page, suppose we want to call a javascript function or make a ajax request at the end of the scroll or near about.

Jquery scroll window to top bottom and absolute positions

Recently i have posted how to make Social share buttons in asp.net, Making slider of html content with pagination in jquery , javascript close current window without prompt in ie , Select all div text in single click in JavaScript and now i am going to explain how to scroll window from jquery and make functionality like Scroll To Top, Scroll To Bottom, Scroll To An Absolute Position or just to a control from jquery.

C# Custom Datetime Format String

Many Date times format patterns are available in c# asp.net, you can use them and get custom format as you required, DateTime Type have the method ToString that can be use to get custom datetime format just pass the string format.

Below is the many letter format provided by Datetime type ToString Method and expected result given in small bracket definition is given in bold string after equal. 

How to get parameter from url string in c#

Recently i have posted get parameter from url javascriptCheck/Uncheck all checkboxes of a gridview in javascriptHighlighting text inside div in JavaScript and now i am going to explain multiple ways to get parameter from url string or given query data in asp.net.

Get youtube video thumbnail image in asp.net

Here is an example for how to obtain a url of thumbnail image of a youtube video programmatically in asp.net, get youtube video thumbnail in asp.net.

Below is the code that returns image thumbnail url of given youtube video url by passing video url as a parameter in GetYouTubeImage method.

Calling a method of parent page from user control

In my previous post i explained about how to handle events of usercontrol in parent page in asp.net and here i am going to explain

How to call a function from a usercontrol on the Parent form.

All you need to pass a event to the parent page to call method across the page and control, you can call parent page methods in usercontrol as well as usercontrol methods in the parent page through the concept of events and delegates.

Handle events of usercontrol in parent page in asp.net

Some time we need to make a global functionality for our project then we think about usercontrol and call it to the webpage but what about when all common functionality remains same but some controls event functionality varies according to the page, means we need button click or check box check change or dropdown selected index change event on the parent page.

How to upload a file in asp.net using fileupload control c#

Here is an example which is for how to upload and save a file through fileupload control in asp.net c# with validating files content type, size of file and extension of file as you want .jpg or .png etc.

Regular expression for alphanumeric with space in asp.net c#

How to validate that string contains only alphanumeric value with some spacial character and with whitespace and how to validate that user can only input alphanumeric with given special character or space in a textbox (like name fields or remarks fields).

In remarks fields we don't want that user can enter anything, user can only able to enter alphanumeric with white space and some spacial character like -,. etc if you allow.

Some of regular expression given below for validating alphanumeric value only, alphanumeric with whitspace only and alphanumeric with whitespace and some special characters.

regex - check if a string contains only alphabets c#

How to validate that input string contains only alphabets, validating that textbox contains only alphabets (letter), so here is some of the ways for doing such task.
char have a property named isLetter which is for checking if character is a letter or not, or you can check by the regular expression  or you can validate your textbox through regular expression validator in asp.net.

Following code demonstrating the various ways of implementation.

Reverse number program in c#

Reversing given number without using any built-in function or method just use only basic function, this is often asked question in the interview.

Following sample code is for reversing number using simple basic function, method takes only a number as input and returns reversed number of given input number in c#.

Get max occurred character in string in c#

Most of the time in interview (fresher or 1 year) interviewer asks this questing and says that not to use inbuilt function use only basic function and find maximum occurring character for a string entered as well as find the no of occurrence of that character.

Following code find the maximum occurring character in the given string it takes string as a input and returns maximum occurred character as char of that string.

Typing Text Effect In Javascript

Most of the time we need to create a effect just like typing text in web page but don't know how to do such task through javascript.
 
This article is for creating typing effect for given text through javascript, below is auto started, manual through started through button click demo is given below.

Moving Viewstate Bottom Of Page

Most of the time we need to make our website search engine friendly for the better monetizing our site and for moving our site to top of the search result on search engine, for that we need to follow some of the rules provided by search engine and one of them is to move your page viewstate from head to bottom of the page for getting better search engine spidering.

Compressing viewstate in asp.net

Viewstate as we know basically is a serialized data which stores in pages in the form of hidden fields. As we know that viewstate stores in the page so it makes page size larger (increase page data size), so if your viewstate is not much there is no problem but if viewstate is enough larger then it would be the cause of slower page load and decrease

Preventing re-execution of method when press browser's refresh button

Often we see that after executing a functionality by a button click (through posting a form to server), when we click on browser refresh button then a pop up re-sending previous page information to server shows and after clicking resend (retry in IE) that particular functionality re-executed i.e reinsertion occurs in database or some other functionality that previously had been done.

Recent Article