I found a problem on ASP.net web Applications with read only text boxes not responding to the ‘viewsate’ property set, If you set the ‘readonly’ attribute to true. It will clear the readonly text box text up on postback.

<asp:TextBox ID=”companyTextBox” runat=”server” InvalidColor=”#ff0000″
MinimumPrefixLength=”3″ EnableViewState=”true” ReadOnly=”true”/>

The solution for avoiding clearance was to add the ‘readonly’ property at the run time on the event of each page load.

protected void Page_Load(object sender, EventArgs e)

this.companyTextBox.Attributes.Add(“ReadOnly”, “true”);


At the moment  I cannot understand how this happens. But will find out soon.




.net 3.5 Linq queries does not seem to support date comparison. For example following code did not support.

entities.Object.Where(p => p.ToDateTime.Date>=DateTime.Now.Date
&& p.FromDateTime.Date<= DateTime.Now.Date)

But it supported comparison of date time.

entities.Object.Where(p => p.ToDateTime>=DateTime.Now
&& p.FromDateTime<= DateTime.Now)

Finally found a solution to compare the Date only trough linq query

entities.Object.Where(p => p.ToDateTime>=DateTime.Today
&& p.FromDateTime<= DateTime.Today)

Note:In my case the date object stored in the database recorded 00:00 as its time. In C# with the  DateTime.Today it sets the time to 12:00AM which is 00:00 in SQL.

This worked for me. Hope it’s helpful to you as well

This is what I just found hope it is use full @ some point


Here is the code I used to open out look and set the to address and tittle and to do a attachment to that mail.

application.Visible = true;

book.SaveCopyAs(@”” + ConfigurationSettings.AppSettings[“Reports”] + “Course Schedules for “ + lblProviderName.Text + “.xls”);

Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

message.Subject = “Course Schedules for “ + lblProviderName.Text + ” (“ + this.providerNumber + “) “;


message.Body = “”;

int attachmentLocation = 1;

message.Attachments.Add(“” + ConfigurationSettings.AppSettings[“Atachments”] + “Course Schedules for “ + lblProviderName.Text + “.xls”, Outlook.OlAttachmentType.olByValue,

attachmentLocation, “Course Schedules for “ + lblProviderName.Text + “.xls”);


Here is the code for creating a new Microsoft excel file open it and open a new sheet of it and to insert data from the data table to it and save the a copy of a application in your hard drive.

Excel.Application application;

Excel.Workbook book;

Excel.Worksheet sheet;

application = new Excel.ApplicationClass();


DataTable dt = new DataTable();

dt = dtCouseSchedule.Copy();

book = application.Workbooks.Add(Type.Missing);

sheet = (Excel.Worksheet)book.Worksheets[1];

sheet.Name = “SampleExcel”;

for (int i = 1; i <= dt.Rows.Count; i++)


      for (int j = 1; j <= dt.Columns.Count; j++)


   ((Excel.Range)sheet.Cells[i, j]).Value2 = dt.Rows[i – 1].ItemArray[j – 1].ToString();




application.Visible = true;

book.SaveCopyAs(@”” + ConfigurationSettings.AppSettings[“Reports”] + “Course Schedules for “ + lblProviderName.Text + “.xls”);

This is one of the most asked questions by a beginner in the C# devlopment

SqlConnection SqlCon = new SqlConnection(connectionString);


SqlCommand SqlCmd = new SqlCommand(cmdtxt, SqlCon);