Skip to main content

Posts

Showing posts with the label C#

For Localize Datetime in Windows Application

  private void Form1_Load(object sender, EventArgs e)         {             // Creating a Global culture specific to our application.             System.Globalization.CultureInfo cultureInfo =new System.Globalization.CultureInfo("en-US");             // Creating the DateTime Information specific to our application.             System.Globalization.DateTimeFormatInfo dateTimeInfo =                 new System.Globalization.DateTimeFormatInfo();             // Defining various date and time formats.             dateTimeInfo.DateSeparator = "/";  ...

Ms Excel in C#,VB.Net Could not find installable ISAM

When you are going to use Ms Excel in c#, If you get this error when importing a excel  file  use this connection string  Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +Server .MapPath("Master.xlsx") + ";Extended Properties='Excel 12.0;HDR=YES;'"  "HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite. 

Print Div ,HTML or Table Content in Asp.net Using C#

Following is the code for printing  Div ,HTML or Table to printer using C# in Asp.net < script type ="text/javascript" language ="javascript">     function print()     {     var printFriendly = document.getElementById( "div1" )     var printWin = window.open( "about:blank" , "Voucher" , "menubar=no;status=no;toolbar=no;" );     printWin.document.write( "<html><head><title>Voucher Report</title></head><body><h1>Agent Wise Report</h1>" + printFriendly.innerHTML + "</body></html>" );     printWin.document.close();     printWin.window.print();        printWin.close();     }         </ script > add this script lines in your header section of given page. < div id ="div1"> < table ...

How To remove/delete Row in a DataTable of DataSet C#.Net

I created one table using DataTable by programming, i have save this DataTable in Session in Asp.Net using C#. DataTable dt = (( DataTable )Session[ "productds" ]); DataRow dr = dt.Rows.Find(SearchValue); dt.Rows.Remove(dr); dt.AcceptChanges(); First get the DataTable from Session into dt object using casting. After that find the DataRow  that has contain that unique value using Find() Method of DataTable dt, it will return the Datarow dr that matches the SearchValue.Then call Remove() method to delete row from DataTable dt,after that call  AcceptChanges() method of DataTable dt to apply chages to DataTable.

DataView Rowfilter With Like % in C#.Net

DataView RowFilter Syntax in C#,ASP.Net Example This example describes syntax of DataView.RowFilter expression. It shows how to correctly build expression string (without "SQL injection" ) using methods to escape values. Column names If a column name contains any of these special characters ~ ( ) # \ / = > < + – * % & | ^ ' " [ ], you must enclose the column name within square brackets [ ]. If a column namecontains right bracket ] or backslash \, escape it with backslash (\] or \\). [C#] dataView.RowFilter = "id = 10″; // no special character in column name " id " dataView.RowFilter = "$id = 10″; // no special character in column name " $id " dataView.RowFilter = "[#id] = 10″; // special character " #" in column name "#id" dataView.RowFilter = "[[id\]] = 10″; // special characters in column name " [id] " Literals String values are enclosed within single qu...

ASP.Net : The test form is only available for methods with primitive types as parameters

I made a webservice but some methods cannot be tested, I get following message:   The test form is only available for methods with primitive types as parameters.    when click on the service it display this irritating message. I found that this could also be due to passing the variables in the Method definition as ref.  I removed in marked in red circle to solve the problem.  

C#.Net : Create a Class

This is how we can define a Class in C#.Net Here we code to create a class named Student has three member variables,one constructor and properties such as Name,Age. Public Class Student     {         private string name;         private string id;         private int age;         public Student( string name, string id, int age)         {             this.name = name;             this.id = id;             this.age = age;         }         public string Name         {    ...

ASP.Net : Send mail through Html

Add this page to your project with name of mail.asp and save following code into it. <% if Request.ServerVariables("REQUEST_METHOD") = "POST" then     txtname = Request.Form("txtname")     'txtcompanyname= Request.Form("txtcompanyname")     txtadd = Request.Form("txtadd")     txtzip= Request.Form("txtzip")     txtcity = Request.Form("txtcity")     txtstate = Request.Form("txtstate")     txtcountry = Request.Form("txtcountry")     txtph = Request.Form("txtph")     txtfax = Request.Form("txtfax")     txtemail = Request.Form("txtemail")     txtquery = Request.Form("txtquery")     MailBody="Enquiry Form <br>" _              & "Name: " & txtname & "<br>" _              ...

Asp.Net :How to clear all ASP.Net control content in one method C#

You can call this function to clear content of  controls such as TextBox, CheckBox and  DropDownList. You can further add on other ASP.Net controls to clear their content. public void ClearFields(System.Web.UI.Page page, string defaultDropDownValue) { ArrayList all = GetControls(page.Controls); for (int i = 0; i Many Asp.Net new programmer do it by clear  control content by setting their property one by one . For Ex. TextBox1.Text=""; checkBox1.checked=False;

Interview Questions on DotNet Framework

1. What is CLR? The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (similar to the Java Virtual Machine or JVM in Java), which handles the execution of code and provides useful services for the implementation of the program. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging. 2. What is CTS? Common Type System (CTS) describes how types are declared, used and managed in the runtime and faci...

Check Textbox input is Numeric , C#.Net

Many new programmer face a problem to checking whether textbox input is numeric or not. So you can easily implement this code on your windows form. Call this function on textbox1_Keypress event and it will prevent to enter non-numeric character in textbox.This code only accept integer value and works in Window Application. <code><span>public static bool CheckNumber(char ch) { if (Convert.ToInt32(ch) == 8 ) return false; if(char.IsDigit(ch)==false) return true; return false; }</span></code> Call this function as follows <code>private void txtBox1_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = CheckNumber(e.KeyChar, ((TextBox)sender).Text); }</code>

Get Country Name Through IP Address

There are situations where we have to track visitors. The tracking might include the country from the visitor has browsed the website. These statistics are often important. The major advantage of this method is a single DLL. It does not require any database setup etc. You just need to add reference to the IpToCountryLib DLL provided in the solution. To resolve the country name, the library API to be used is "GetCountry". GetCountry takes in a string parameter which is the IP Address and returns the country name as the out parameter. This is the code of the function, C# public bool GetCountry(string userHostIpAddress, out string countryName) { bool result = false; countryName = string.Empty; if (string.IsNullOrEmpty(userHostIpAddress)) return false; IPAddress ipAddress; if (IPAddress.TryParse(userHostIpAddress, out ipAddress)) { countryName = ipAddress.Country(); result = true; } return result; } To use the function you will do a call like this, C#, string country; GetCountry(...

Managing State with ASP.NET and C#

Web Applications are disconnected in nature which means that there is no way for the browser to know who is using the application at present time. In classic Asp programming maintaining state was a headache for the developers. They had to write alot of code to maintain state. But Asp.net model provides easy state management. In this article we will see how we can persist state in multiple pages so the user is recognized by the browser. Preserving State in Web ApplicationsThere are number of ways that you can use to preserve the State of the Web Application. Here are some of the possible ways listed. 1) Using Cookies (Client Side State Management technique) 2) Using Session States 3) Using Application States 4) Using HttpContext collection 5) Using ViewState (Client Side State Management technique) These are only some ways of storing the state of the user as well as the application. In this article we will see few of them in detail.