Ads 468x60px

Sunday, May 29, 2011

how to find the dates on sundays in a specific month using with c#

First of all add the following NameSpace in your .aspx.cs File
using System.Globalization; 
protected void Page_Load(object sender, EventArgs e) 

DateTime currentDateTime=System.DateTime.Now; 
int year=currentDateTime.Year; 
int months=currentDateTime.Month; 
GetDatesOfSundays(year, months, DayOfWeek.Sunday); 

protected void GetDatesOfSundays(int year, int month, DayOfWeek dayName) 

CultureInfo ci = new CultureInfo("en-US"); 
for (int i = 1; i <= ci.Calendar.GetDaysInMonth(year, month); i++) 

if (new DateTime(year, month, i).DayOfWeek == dayName) 
Response.Write(i.ToString() + ","); 

Saturday, May 28, 2011

How to Convert Date Time Format in using C#

In this tutorial you will learn how to convert Date Time Format in using C# programing language in an easy way. just copy and past the code below and find the solution of your problem.
Today Date Time Formate:
Result will be: 05/29/2011

Monday, May 9, 2011

User Counter

just copy and past the code, this snipt will help you to count visits on your website, no need to build any database it will use an xml file light weight code using c#.NET. Code for .aspx.cs file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UC_UserHIT_Counter : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)

        DataSet tmpDs = new DataSet();
        lbl_Counter.Text = "<b><font color='blue'>Total Visits:</font></b> <font color='green'>" + tmpDs.Tables[0].Rows[0]["hits"].ToString() + "</font> ";
    private void countMe()
        DataSet tmpDs = new DataSet();
        int hits = Int32.Parse(tmpDs.Tables[0].Rows[0]["hits"].ToString());
        hits += 1;
        tmpDs.Tables[0].Rows[0]["hits"] = hits.ToString();
Code for .aspx file.
just put it any where in the aspx file.
<asp:Label ID="lbl_Counter" runat="server"></asp:Label>

File upload in using C#

if (file_upload.HasFile)
                string filepath = file_upload.PostedFile.FileName;              
                string file_ext = Path.GetExtension(this.file_upload.PostedFile.FileName);              
                string filename = Path.GetFileName(this.file_upload.FileName);
                string newName =  filename.Replace(filename, CompleteName);
                string Datenew =  DateTime.Now.ToString("g");              

                DateTime dattime = new DateTime();
                dattime = DateTime.Now;
                string date = dattime.Date.ToString("d", DateTimeFormatInfo.InvariantInfo);
                string[] split;
                split = date.Split('/');
                string month = split[0];
                string day = split[1];
                string year = split[2];
                string time = dattime.TimeOfDay.ToString();
                file = newName + month + "-" + day + "-" + year + file_upload.FileName.ToString() + "";
                file_upload.PostedFile.SaveAs(Server.MapPath(@"~/Dynamic/userPics/") + file);