C# - C Sharp
codes, tips, and tutorials about C#
Storing files to database and downloading it using ASP.NET

1) First create a new column and set it as varbinary(MAX) for the datatype. 2) Use this code to store the file to database:             //Read File to Bytes                     FileStream st = new FileStream(<Location of the file>, FileMode.Open);                     byte[] fileData= new byte[st.Length];                     st.Read(fileData, 0, (int)st.Length);                     st.Close();                     SqlParameter[] param = new SqlParameter[] { new SqlParameter("@ID",<Reference ID>),                                                     new SqlParameter("@Data",fileData)  };             int i = SqlAccessor.ExecuteNonQuery(<ConnectionString>, SqlAccessor.SqlCommandBuilder(new SqlCommand (<Stored Procedure Name>), param), CommandType.StoredProcedure, out retVal);  I've used Application Blocks to simplify data operation. To Retrieve the data and to be downloaded from an ASP.NET Page: 3)  I created a function that returns a byte array with ID as parameter  public static...

posted @ Thursday, November 20, 2008 4:59 PM | Feedback (1)
C# Using ThreadPool for Multi-Threaded Application

I'm currently designing an application specifically to handle multiple processing at a certain time. I've read all articles about threading, whether to use a background worker, custom thread management, or by using a thread pool. What facinates me is the thread pool, just by passing a workitem viola you have a working multi-threaded application. See simple example below: using System; using System.Threading; public class MyProcess {     private ManualResetEvent _doneEvent;     public MyProcess(ManualResetEvent doneEvent)     {         _doneEvent = doneEvent;     }     public void MyProcessThreadPoolCallback(Object threadContext)     {         int threadIndex = (int)threadContext;         Console.WriteLine("thread {0} started...", threadIndex);         StartProcess();         Console.WriteLine("thread {0} end...", threadIndex);     // Indicates that the process had been completed         _doneEvent.Set();     }     public...

posted @ Monday, March 19, 2007 1:01 PM | Feedback (2)
Multi-Language Support in Classic ASP

I was ask to create COM+ that will return data from DB2 to Classic ASP that has multi-language support. At first, it was really a headache on how I can accomplish this project. I've try to just passed the data comming from DB2 directly to ASP but it was totally garbage.I get data from DB2 using Dataset and I loop each rows in the dataset to construct a string, since string datatype is compatible with Classic ASP, My delimiter per row is  "___NLINE__" and per column is  "N$XITM_". Also in order to connect to DB2, I used Ritmo Driver for iSeries, its a third-party driver that...

posted @ Thursday, June 09, 2005 11:35 AM | Feedback (1)