Saturday, 23 April 2011

C# File Stream read/wirte

More File Stream Samples
//******************

FileStream file = File.OpenRead("c:\\siraj\\Post_Check\\" + icb_inputfile);
byte[] buffer = new byte[81];

int c = file.Read(buffer, 0, buffer.Length);
while (c > 0)
{
TXTLine = System.Text.ASCIIEncoding.ASCII.GetString(buffer);

switch (TXTLine.Substring(TXTLine.Length - 3, 2))
{
case "SR":
case "PP":
break;
}
c = file.Read(buffer, 0, buffer.Length);
}

file.Close();

//**********************
//Write Ascii Files
strIssuerFileName = "c:\\Siraj\\" + strIssuerFileName;
StreamWriter sw = new StreamWriter(strIssuerFileName);
sw.Write(strFileText.ToString());
sw.Close();

C# Quick Ref



Creating c# class instance using static method

using System;
using System.Collections.Generic;
using System.Text;

namespace OrderFulfellmentServices.Models
{
   public class Class1
   {
       public Class1()
       {

       }
       public static Class1 Instance
       {
           get
           {
               return new Class1();
           }
       }
       public string getBestBuddy()
       {
           return "best buddy";
       }
   }

}


the caller



       public void Callermethod()
       {
...
           var st = Class1.Instance.getBestBuddy();

       }

-----------------------------------



SQLDataReader


Delegates and events



Add data to database using SqlDataAdapter


Bind related tables and display gridview