Friday, 28 October 2011

Read External Config File in .NET

First, u must create one file with the extension .config
I named it as Global.config. All the appSettings reside in that file like below:

    <add key="LocalDB" value="Data Source=;Initial Catalog=IMMCFG;uid=jimusr2;pwd=jimusr2"/>
    <add key="LocalDBP" value="Data Source=;Initial Catalog=IMMDBP;uid=jimusr2;pwd=jimusr2"/>
    <add key="JIMDBP" value="Data Source=;Initial Catalog=JIMDBP;uid=jimusr2;pwd=jimusr2"/>
    <add key="IMMDBP" value="Data Source=;Initial Catalog=IMMDBP;uid=jimusr2;pwd=jimusr2"/>
    <add key="SERVER" value="XPS1640-PC" />
    <add key="DB" value="IMMCFG" />
    <add key="DB1" value="JIMDBP" />
    <add key="DB" value="IMMCFG" />
    <add key="DB1" value="JIMDBP" />
    <add key="UID" value="sa" />
    <add key="PWD" value="password" />
    <add key="AppVersion" value="1.2"/>
    <add key="ClientSettingsProvider.ServiceUri" value="" />

then, your application config file should look like this:

 <appSettings file = "../CONFIG/Global.config">


Thursday, 6 October 2011

Report Viewer – “More than one data set” Error

Today I got a best solution to solve “More than one data set, data region, or grouping in the report has the name ‘Assembly Name’. Data set, data region, and grouping names must be unique within a report.”

This error came out due to duplicate data sets in the .rdlc file you created for your report. In my case this occurred when I was using an object data source.

To solve this error,  right-clicking the .rdlc file in the Solution Explorer, selecting Open With, and then XML Editor you’ll be able to see the XML that makes up the report you are designing. By collapsing the “DataSet” elements found within the “DataSets” element you’ll quickly see the duplicates. By expanding the elements back out, scrolling down and finding the “rd:ObjectDataSourceType” element you’ll see what is going on.

All of this I refer to

Wednesday, 27 April 2011

How to solve Value cannot be null.Parameter name: activationContext

Go to project's properties, then to security and uncheck Enable ClickOnce Security Settings.
Hope this will help

Monday, 18 April 2011

Auto Update for windows appliction in C#

Last week I learn an interesting lesson about using auto update for windows applications.
This auto update will update the application in client computer when the is a new update for the application. This can be done by wyupdate. It is open source.

All the file can be place in one server, and the client's pc will point into the server to check whether got new update or not. This can be done by autoupdate or user click one update's button.

Monday, 11 April 2011

Database is down

Argghhh!!! Today too many table change in the database, so database already down for more than 2 hours. All developers are stuck with their job. Waste lot of time.

As I heard from my seniors, this is the common situation in project development; table change, database always down, requirement change and etc. So this is the challenge of project development and it is a big project. Many said that we will learn a lot of things if we involve in project development.

Wednesday, 30 March 2011

Final Year Project

Just wanna share with u guys about my final year project for my bachelor's degree. My final year project is about GIS (Geographical Information System). The title for this project is Equipment Management System for Paya Indah Wetlands. FYI, Paya Indah Wetlands is one of the recreation park in Malaysia. This system is to manage the schedule the use of equipments in this park using the map. So, here is the main screen for this system. This system I develop using PHP and Advance Javascript.

There are 3 users; admin, clerk and staff. This is the login screen for all users. It will differentiate by the role of each user. So here I just put the preview of my screen. Later I will explain more.

Tuesday, 29 March 2011

Direct printing in C# windows application

Just wanna share with u all about the direct printing in the C# windows application. This is little bit tricky for me at first because there are so many things about printing in C# that I need to learn. So, here is my code for direct printing. You can design your report in rdlc.

private void Print_Click(object sender, EventArgs e)
BasePrint printForm = new BasePrint();
                ReportDataSource reportDataSource = new ReportDataSource();

                printForm.Report.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                reportDataSource.Name = "General_PPT_pptAcception"; <--link to the object for data (the  namespace: General.PPT.pptAcception

                DataTable dt = Util.ConvertDataTable(pptTerima);
                reportDataSource.Value = dt;

                ReportViewer ReportViewer = new ReportViewer();

                ReportViewer.LocalReport.ReportEmbeddedResource = "PrintForm.rdlc";


                Print(Convert.ToInt16(Copy.Text.Trim())); <--number of copy


Also include all this code:

    #region direct printing
        public void Dispose()
            if (m_streams != null)
                foreach (Stream stream in m_streams)
                m_streams = null;

        private Stream CreateStream(string name,
      string fileNameExtension, Encoding encoding,
      string mimeType, bool willSeek)
            Stream stream = new MemoryStream();
            return stream;
        // Export the given report as an EMF (Enhanced Metafile) file.
        private void Export(LocalReport report)
            string deviceInfo =
            Warning[] warnings;
            m_streams = new List<Stream>();
            report.Render("Image", deviceInfo, CreateStream,
               out warnings);
            foreach (Stream stream in m_streams)
                stream.Position = 0;
        // Handler for PrintPageEvents
        private void PrintPage(object sender, PrintPageEventArgs ev)
            Metafile pageImage = new

            // Adjust rectangular area with printer margins.
            Rectangle adjustedRect = new Rectangle(
                ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
                ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,

            // Draw a white background for the report
            ev.Graphics.FillRectangle(Brushes.White, adjustedRect);

            // Draw the report content
            ev.Graphics.DrawImage(pageImage, adjustedRect);

            // Prepare for the next page. Make sure we haven't hit the end.
            ev.HasMorePages = (m_currentPageIndex < m_streams.Count);

        private void Print(short pages)
            if (m_streams == null || m_streams.Count == 0)
                throw new Exception("Error: no stream to print.");
            PrintDocument printDoc = new PrintDocument();
            printDoc.PrinterSettings.Copies = pages;
            if (!printDoc.PrinterSettings.IsValid)
                throw new Exception("Error: cannot find the default printer.");
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                m_currentPageIndex = 0;