c sharp (c#) questions and answers

1. How to check whether a checkbox is checked or not in c sharp (c#)

if (checkBox1.Checked)

MessageBox.Show(“The checkbox1 is checked”);

if (checkBox1.Checked == false)

MessageBox.Show(“The checkbox1 is not checked”);

2.How to create a boolean array in c sharp (c#)

Boolean[] var = new Boolean[8];

3.How to replace string in c sharp (c#)

string str = “hai how r u”;

MessageBox.Show(str);        // o/p : hai . . . → Read More: c sharp (c#) questions and answers

Get folder names using c# windows application

Get the folder names from the parent folder and store those names
in the excel sheet in c# windows application.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;

namespace File_Names
{
public partial class FileNames : Form
{
public FileNames()
{
InitializeComponent();
}

// Browse for parent folder

private void Browse_Click(object sender, EventArgs e)
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.ShowDialog();
textBox1.Text = folder.SelectedPath;
}

// Entire logic for . . . → Read More: Get folder names using c# windows application

Programming in c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Good_Developer : Form
{
public Good_Developer()
{
InitializeComponent();
}

// Browse only text/excel files
private void Browse_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = “.txt|*.txt|.excel|*.xls”;
openFileDialog1.FileName = “”;
openFileDialog1.ShowDialog();
textBox1.Text=openFileDialog1.FileName.ToString();
}

private void Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}

// In the properties menu bar–>click on Events
// Enter only numbers in the textbox
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsDigit(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = . . . → Read More: Programming in c#

How to create a Webserive through dotnet :

How to create a Webserive through dotnet :

File–>New–>Project–>Visual C#–>Web—>ASP.NET Web Service Application

It will automatically loads some code in the file

1.Webservice for Hello World and Temperature Convert

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace TempConvert1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, . . . → Read More: How to create a Webserive through dotnet :

Browse only specific files in c# windows application

How to browse only specific files using c# windows application

(Ex:User can able to browse only text files or

User can able to browse only text and xml files )

Drag OpenFileDialog from Toolbox—Dialogs and one textbox and one button

private void Browse_Click(object sender, EventArgs e)

{

// User can able to select only text and xml files

openFileDialog1.Filter = “.txt|*.txt|.xml|*.xml”;

openFileDialog1.FileName . . . → Read More: Browse only specific files in c# windows application