Archive for the ‘ C# ’ Category

Number Only TextBox C# Windows Application

Put this code snippet your TextBox KeyPress Event, you will have your Number Only TextBox Working.

private void numberOnlyTextBox1_KeyPress(object sender, KeyPressEventArgs e)
 //allow digits only
 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
   e.Handled = true;

 // allow one decimal point
 if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
  e.Handled = true;

A Rahim Khan

Adding ReportParameter in Microsoft Report Viewer 2010

I Started using Microsoft Report these days, struggled a bit with ReportParameter. This following code shows how to use ReportParameter with Microsoft Report Viewer 2010.

Class1 cl1 = new Class1(); cl1.One = "1"; cl1.Two = "123"; cl1.Three = "123";

reportViewer1.LocalReport.ReportPath = @"E:\ImageExperiment\ImageExperiment\ImageExperiment\Report2.rdlc";

reportViewer1.LocalReport.EnableExternalImages = true;

List param1 = new List();
param1.Add(new ReportParameter("ReportParameter1", @"C:\a1.jpg"));
param1.Add(new ReportParameter("ReportParameter2", @"C:\a2.jpg"));
param1.Add(new ReportParameter("ReportParameter3", @"C:\a2.jpg"));

Class1BindingSource.DataSource = list;


A Rahim Khan

2011 in review

The stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 72,000 times in 2011. If it were an exhibit at the Louvre Museum, it would take about 3 days for that many people to see it.

Click here to see the complete report.

How to delete files from a specific folder using datetime constraint (C# code)

To delete files from a specific folder you can use following code snippet written in c#.

foreach (FileInfo fileInformation in new DirectoryInfo(@”I:/TrialTesting/”).GetFiles())

Continue reading

ASP.NET File Upload and Download

ASP.NET File Uploader is an easy to use control. Just drag and drop the control on your page and write this code snippet at Button Click Event to upload the file.

if (studentFileUpload.HasFile == true)
  string filename = Path.GetFileName(studentFileUpload.FileName);
  studentFileUpload.SaveAs(Server.MapPath("~/DataFile/") + filename);

Continue reading

How to set Crystal Report Header in Visual Studio 2008

I wasted almost a day searching on google to resolve this issue. If you want to set some values or title of report dynamically from code behind, you can use this following code snippet.

string amount = amountTextBox.Text;
string titleString = "        Total Sanctions above  ";

List investmentList = new List();
investmentList = new InvestmentManager().CollectAmountWiseInvestment(amount);

expirySanctionCrystalReport reportDocumentObject = new expirySanctionCrystalReport();

//Set Crystal Report Header 
CrystalDecisions.CrystalReports.Engine.TextObject amountText = (CrystalDecisions.CrystalReports.Engine.TextObject)reportDocumentObject.ReportDefinition.ReportObjects["dateText"];
amountText.Text = amount;

CrystalDecisions.CrystalReports.Engine.TextObject titleText = (CrystalDecisions.CrystalReports.Engine.TextObject)reportDocumentObject.ReportDefinition.ReportObjects["TextTitle"];
titleText.Text = titleString;

amountWiseCrystalReportViewer.ReportSource = reportDocumentObject;
amountWiseCrystalReportViewer.Visible = true;

Continue reading

C# Numeric Validation

C# does n’t have any built-in function to validate Numeric Data Type. you can write a simple function to validate Number using TryParse Method of Double Data Type. This will return true or false is subject to the argument is Numeric or not. Continue reading