Thursday, 5 March 2015

showing viewdata in MVC 5 on razor view

In MVC Viewdata is the way to maintain the data for passing it  from Controller to View.

Just giving the below example to pass the ViewData in MVC5 on Razor View;

You have defined or pass the Viewdata from controller like below;

public class HomeController : Controller
    {
        //
        // GET: /Home/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult MyHomeview()
        {
            ViewData["Datetime"] = DateTime.Now.ToString();
            return View();
        }
       }

Saturday, 28 February 2015

read json in c#

Reading the JSON file passing from Jscript file and read that in C# Code

Suppose you are creating the JSON file like below;

function GetInsertedData() {
    var CustomerDetailsModels = {
        CustomerDetailId: $("#hdnId").val(),
        ClinicName: $("#txtClinicName").val(),
       PhoneNumber: $("#txtPhoneNumber").val(),
        UserName: $("#txtUserName").val(),
        Password: $("#txtPassword").val(),
        // DateOfRegistration: $("#DateOfRegistration").val(),
        ValidaityDate: $("#txtValidaityDate").val(),
        ActiveDate: $("#txtDateOfActivation").val(),
        Address1: $("#txtAddress1").val(),

        Address2: $("#txtAddress2").val(),
        CountryId: $("#ddlSelecteCountry").val(),
        StateId: $("#ddlSelectState").val(),
        DisctrictId: $("#ddlDistrict").val(),
        PinCode: $("#txtPincode").val(),
        EmailId: $("#txtEmailID").val(),
        Website: $("#txtWebsite").val(),
        OfficeNumber: $("#txtOfficeNumber").val(),
        NumberOfUser: $("#ddlAllowedNumberUser").val(),
        IsActive: $("#chkISActive").val(),
        IsPaid: $("#chkISPaid").val(),
        AmountPaid: $("#txtPaidAmount").val()

how to read class property name in c#

Dynamically retrieve and save property name and value into the database That can be possible if you are able to read the class property dynamically, and later on retrieve it from the database and invoke the property values

If you have already get work done that how to save the property name in the database, then use Get Property is the way to go on the retrieval of property.

Use Gettype to get the class types. 

Saturday, 20 December 2014

Generate pdf using rdlc c#


In this article I will demonstrate you how to create rdlc report in asp.net.

Microsoft made it very simple to generate PDF by using the “Microsoft.ReportViewer.WebForms”
Take the reference of Microsoft.ReportViewer.WebForms to work with RDLC. It will appear in your reference folder like below;

clip_image001

Thursday, 18 December 2014

Convert number to words c# code


In many applications you need to convert numbers into words like in bank statement invoice or converting the currency values into words.
Below application will really help you to convert the numbers into words.
You just need to pass the numbers like; “23456” it will convert Twenty Three Thousands Four Hundred Fifty Six.

Application will support till the lakhs if you want to extend it you can extend till what you need.


Friday, 12 December 2014

stylecop visual studio

 

A simple design page : When inserting the Name checking the text value

 

image

Setting of Style Cop Rules and Properties

image

 

Rule Selection

a) Click on the check box to check or uncheck the rules to apply for code analysis, By default it is checked for all rules

image

Company Information

image

Run the style Cop to check the code analysis

Either from Toolsà Run the Style Cop

Or Right click on project explorer à Run the Style Cop

image

 

When you run it it will give the Warnings if it will break the rules.

image

On Running the Style Cop

image

Output Code snippet

After rectifying all the warning by Style cop getting result Violation count : 0

image

Exclude the Particular File from Style Cope

image

Creating Custom Rule

Steps to Creating Custom rule

1> Creating One Class Library file

2> Import the two DLL and reference it to project

using Microsoft.StyleCop.CSharp;

using Microsoft.StyleCop;

From C:\Program Files\Microsoft StyleCop 4.4.0.14

3> Add one XML File for configuration

4> Successfully Build the code in Release mode

5> Place the DLL into

C:\Program Files\Microsoft StyleCop 4.4.0.14

Code Snippet for Custom Rule to Check Data Base is Closed or Not “.CS file”

image

XML Code Snippet

image

Get the Custom Style Cop Rule into project

image

Custom Warning

image

Tuesday, 9 December 2014

c# combine multiple pdf into one

 
*Note : Take reference of itextSharp API DLL reference to work with below application

We were facing the problem of creating the multiple PDF file and send it to clients. So they have to take the print of PDF one by one so, created the application to combine multiple PDF files into one PDF.


clip_image001


Friday, 28 November 2014

vs2013 New Features


Feedback & Notifications

In VS2013 product we can provide the feedback about the product
There it provided different options and you can Report to the Bug to Microsoft directly also
image
  You can see the latest updates on product by seeing the notification from clicking the icon. It will give the count of notification on flag icon just beside of quick launch.


image


Code Lens

This is wonderful features introduce by VS2013, by using it you can see the references of particular method, Constructor and Class in your application in one instance.
image
Just keep the mouse over there it will give you the information of all the references and for more detail you can click so it will redirect to that piece of code or just put the mouse so it will show you the code.
image


Peek Definition

In Previous version of Visual studio, to get the definition of any function we need to do F12 and it will redirect to respective method. Now with the feature of F12 Microsoft introduce feature of Alt + F12. It will open a window in same page, which have function definition.
Just do Alt + F12 or Right click on Method.
image
You will get the peek definition as below; Than page will open which the piece of belongs to
image


Code Preview Scroll Bar

You can customize the Scroll bar for your code preview and it improve the functionality of viewing the code.
image
Scroll will be look like a narrow code window and on doing the mouse over to the scroll it will be look like the left screen.


CodeMap – On Debugging (flow chart Display)

It helps to analysis the flow of the code at time of debugging.
Code map Icon will be visible at the time of debugging and when you click on it, it will open the Call stack.
image
On Right side window will be open which is having the Call stacks with the list of method that pass and list of method will come. It shows the list of debug point in the methods and where exctly we are also.
image

New Blue Theme

Microsoft Introduces theme in VS2012, Now they increase the collection of themes and introduce the blue theme.
You can choose the themes from Options à General
image
Blue theme will look like vs2010 IDE
image


Navigate To By Ctrl+,
Using the new Navigate To, smart semantic search will open and there you can type the method name or Class name it will open in the list with the search;
Just Type the ctrl + , and search you are looking for and by clicking on search result it navigate to search result.
image
 
Enhanced Scrollbar
Enhanced Scrollbar provides the vertical scrollbar a visual cues.
It mark the scroll bar with Quick view for debug point, Unsaved Value, Error, Current Position and Search result.
It brings the information into finger tips and when you click on that mark it open that piece of code where the mark belongs to.
image


Auto Brace Complete
Auto Brace is the power tool feature introduces in vs2013, As pet it parenthesis, Braces and Quotes will automatically
added for you when you open it.
image


Move Line Up/ Down
One another feature for power tool, you can move up or down the selected piece of code by using alt + arrow up and
down by alt + arrow Down
image






Monday, 10 November 2014

sequence of events in master page and content page

In your application if you are using Master page, Content Page (Child Page) and User controls. Page life cycle for different pages have different events. Below content you can see the  Sequence of events for Master Page, Content Page and User Controls.

Problem: Why its required?
Many time its happen that you need the value of master page into Child page or the user control page into Webpage. Then from below description you will know that what is the possibility.

Creating the three file in application.
1. Site1,Master
2. WebForm1,aspx
3. WebUserControl1.aspx

Saturday, 1 November 2014

Converting String to Int in C#

String is the reference type in C# and int is the value type.(What is Ref and Value type )
So, The way of maintain the memory location are quite different for both of them and to converting the value to refrence is called boxing in C#.

If you see the below program;
static void Main(string[] args)
        {
            int i = 123;
            string str = "123";

            if (str.Equals(i))
                Console.WriteLine("Success");
            else
                Console.WriteLine("fails");

        }