Posted by Catur Nugroho | File under :
Simple Code to Using Html Agility Pack

So i have a code of Htmlagilitypack in my mind and hopefully what I get can be useful for those.
Lest try! 

Do not forget to add this code in your reference :
using HtmlAgilityPack;

This is firs time, we will take the example of html and put it into the HTML Agility Pack
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(sampleHtml);
  
Get Text Box Value
HtmlAgilityPack.HtmlNode node = new HtmlAgilityPack.HtmlNod();
node = doc.DocumentNode.SelectSingleNode("//input[@id='nameOfId']");
string strValue = node.Attributes["value"].value;

Get Combo Box Text Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectSingleNode("//select[@id='nameOfId']").Elements("option"))
            {              

                   If(node.Attributes["selected"] != null)
                   {
                    strValue = node.Attributes["value"].value;
                    break;                   

                    }
             }

Get Radio Button Value
string strValue = "";
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//input[@name='nameOfName']"))
            {
                if (node.Attributes["checked"] != null)
                {
                   
strValue = node.Attributes["value"].value;
                    break;
                }
            }


Oh, too many in my mind so that I do not remember it clearly. I will update when I get something else or If you need somethings about it you can comment this article and I will answer as soon.
Posted by Catur Nugroho | File under :


It works much like PrizeLive and other such web sites. You are paid for completing offers and clicking on links. Before the first of the year, daily they had at least a dollar's worth of links to click on per day which was fast and easy, but since it's gone down quite a bit. I guess it fluctuates, but I wish I hadn't been lazy since it would have been easy money. You also get 50 cents for each referral, but all money earned in my first payout was from stuff done on the site and included no referrals.

Payment
You are required to having $2.5 in your account before requesting to cash out, but once your account is verified and you have the $2.5 payment is instant to your PayPal account. It's pretty straightforward.

Payment Proof
I received my first payment instantly after I had verified my account. I recommend verifying your account shortly after you set it up. It will take a day or so for the phone verification to go through. Once you're verified, you're good to go.



How To Join
There are no special qualifications to join. I would appreciate it, however, if you signed up you need referral code to completed it.

Goto playstore and search cashpirate then download that software.
1. Install CashPirate.
2. Enter my referral code- CXWPEV and signup to get 500 points if u wont enter then u will get 0 points so it ur wish.
3. You get 50% coins for the first 1000 coins you earn (= 500 coins bonus) and can start making money right away!

when u have 2500 points then u can redeem for 2.5$ paypal cashout u can use ur friend paypal also or for 5000 points for amazon. Youu can easily make 2500 points per week by installing app like ladoooo and completing some survey.



Posted by Catur Nugroho | File under :
How to read text from xps document using C#.

The purpose of this article is a personal note from the author. When the project is lost or forgotten so it is easier to find on this page. For over 2 years ago I use this code and really helped me.

I'm sorry, My English is not very good and and a little difficult to make the article.

The first step please add some this references of dot net class library :
1. PresentationCore.
2. PresentationFramework.
3. ReachFramework
4. System
5. System.Core.
6. System.Data
7. System.Data.DataSetExtensions
8. System.Deployment
9. System.Drawing
10. System.Runtime.Serialization
11. System.ServiceModel
12. System.Windows.Forms
13. System.Xml
14. System.Xml.Linq
15. WindowsBase.

Add this code into your name space :
using System.Threading;
using System.Windows.Xps.Packaging;
using System.Windows.Documents;


Usually I using threading to run the function. You can use the following code :
Thread _thMain = new Thread(new ThreadStart(StepOne)); //StepOne is function.
_thMain.IsBackground = true;
_thMain.SetApartmentState(ApartmentState.STA);
_thMain.Start();


The first way :
private void StepOne()
        {
            List<string> lData = new List<string>();
            using (XpsDocument xpsDoc = new XpsDocument(@"C:\sample.xps", System.IO.FileAccess.Read))
            {
                FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
                Dictionary<string, string> docPageText = new Dictionary<string, string>();
                for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; pageNum++)
                {
                    DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
                    foreach (System.Windows.UIElement uie in ((FixedPage)docPage.Visual).Children)
                    {
                        if (uie is System.Windows.Documents.Glyphs)
                        {
                            lData.Add(((System.Windows.Documents.Glyphs)uie).UnicodeString);
                        }
                    }
                }
            }

            string strText = string.Empty;
            foreach (string strItem in lData)
            {
                if (string.IsNullOrEmpty(strItem))
                    continue;

                strText += strItem;
            }
        }


The second way :
private void StepTwo()
        {
            List<string> lData = new List<string>();
            using (XpsDocument xpsDoc = new XpsDocument(@"C:\sample.xps", System.IO.FileAccess.Read))
            {
                FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
                Dictionary<string, string> docPageText = new Dictionary<string, string>();
                for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; pageNum++)
                {
                    DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
                    foreach (System.Windows.UIElement uie in ((FixedPage)docPage.Visual).Children)
                    {
                        if (uie is System.Windows.Documents.Glyphs)
                        {
                            //lData.Add(((System.Windows.Documents.Glyphs)uie).UnicodeString);
                            string strUnicode = ((System.Windows.Documents.Glyphs)uie).UnicodeString;
                            string strIndices = ((System.Windows.Documents.Glyphs)uie).Indices;
                            string strFormattedLine = "";
                            string[] astrIndices = strIndices.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 0; i < astrIndices.Length; i++)
                            {
                                strFormattedLine += strUnicode[i].ToString();

                                if (astrIndices[i].Contains(","))
                                {
                                    if (int.Parse(astrIndices[i].Substring(astrIndices[i].IndexOf(",") + 1)) > 150)
                                        if (!strUnicode[i].ToString().Equals(" "))
                                            strFormattedLine += " ";
                                }
                            }

                            lData.Add(strFormattedLine);
                        }
                    }
                }
            }

            string strText = string.Empty;
            foreach (string strItem in lData)
            {
                if (string.IsNullOrEmpty(strItem))
                    continue;

                strText += strItem;
            }
        }


The difference in the two ways above is space.
Sometimes we will find a line that does not have the correct limit so we often struggle to define the data that we want.
Example :
The first way :
444444444444444444444 
The second way :
 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

I hope this article can help you in managing text in the XPS documents. 

Good Luck!! 

 
 
Posted by Catur Nugroho | File under :
Simple PDF Automation Using Autoit in C#

The topic for this article is how read the text of a PDF document, export into txt file, and return the results as text or string.

This is code for adobe reader X Version 10.1.3, so if the next time you get some code that doesn't run as well might be due to different versions.

This article will explain clearly how we can make simple PDF Automation. If you can't understanding  the code, I have set up the source code so you can debug the code and you can download it from here.

Let's start the code :

This is the image information from the PDF 

 
Parameters :
Title : "[CLASS:AcrobatSDIWindow]" or "sample.pdf - Adobe Reader"
Text : ""

private void RunButton_Click(object sender, EventArgs e)
{
        //open pdf application
        //change it if you have different pdf version 10.1.3
        string strAcrobatReaderType = "AcroRd32";        string strDir = Application.ExecutablePath.Substring(0,      Application.ExecutablePath.LastIndexOf("\\bin") + 1) + "files\\sample.pdf";
        ProcessStartInfo pInfo = new ProcessStartInfo(@"C:\Program Files\Adobe\Reader 10.0\Reader\" + strAcrobatReaderType + ".exe", strDir);
        Process.Start(pInfo);


       //wait the window is opened
       autoit.WinWaitActive("[CLASS:AcrobatSDIWindow]", "", 50);
       if (autoit.WinExists("[CLASS:AcrobatSDIWindow]", "") == 0)
       {
                MessageBox.Show("Windows didn't open");
        }


       //save as text document
       //send keys ALT + f + a

       autoit.Send("!fax", 0);


Save As Image Window Info


Parameters :
Title : "Save As"
Text : ""
Control : Edit1

      string strSaveAsTitle = "Save As";
      string strDir = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\bin") + 1) + "files\\sample.txt";
      int iCountRentry = 0;
     

      //Wait Save As Window is open and check if don't open
      autoit.WinWaitActive(strSaveAsTitle, "", 1000);
      if (autoit.WinExists(strSaveAsTitle, "") == 0)
      {
                MessageBox.Show("Save As Windows didn't open");
       }


       //send keys file directory to save
       do
       {
                if (autoit.ControlGetText(strSaveAsTitle, "", "Edit1").Equals(strDir))
                break;

                //send CTRL + a
                Type("^a", 0, "Edit1", true, 1000, strSaveAsTitle);
                Type(strDir, 0, "Edit1", true, 1000, strSaveAsTitle);

                iCountRentry++;
        }
        while (iCountRentry < 10);
        if (iCountRentry > 10)
        {
                MessageBox.Show("Error sending keys file directory");
        }


Click Save Button Image

Parameters :
Title : "Save As"
Text : ""
Control : Button2
Control Click X : 38
Control Click Y : 10 

        //You have 2 option to save the text document
        //using click button Save As

        Click("left", 1, 44, 12, "Button2", 1000, strSaveAsTitle);

        //or using send key ENTER
        //Type("{ENTER}", 0, "Button2", false, 1000, strSaveAsTitle);

        //read text

        iCountRentry = 0;
        do
        {
                try
                {
                        using (StreamReader reader = new StreamReader(strDir))
                        {
                                 resultTextBox.Text = reader.ReadToEnd();
                        }
                        break;
                 }
                 catch
                
                        Application.DoEvents();
                        Thread.Sleep(1000);
                        iCountRentry++;
                 }
           } while (iCountRentry < 10);

}

Notes :
If this project  didn't working, you have to change some code such as Title, Control, Control Click X and Y. Autoit working because of the screen according to the PC you are using.
Using function of autoit control is better than the others because it is more accurate if used on another PC.

If you getting problems about this please leave a note in the comments so I can help you.

Download Full Source Code 


Posted by Catur Nugroho | File under :

Simple Notepad Automation Using Autoit C#

This is a simple example of how to work with Notepad for sending text, copy / paste, and save it as a file. I will try to explain as details so that you can easily understand.
You can adding this code into your project. This is additional function that I have made, you can copy and paste.

private void Type(string strKeys, int nMode, string strControl, bool blnSleepKeys, int nSleep, string strWindow)
        {
            if (blnSleepKeys)
            {
                char[] achKeys = strKeys.ToCharArray();

                foreach (char ch in achKeys)
                {
                    autoit.ControlSend(strWindow, "", strControl, ch.ToString(), nMode);
                    Thread.Sleep(100);
                    Trace.WriteLine("Sent Key: '" + ch.ToString() + "'");
                }
            }
            else
            {
                autoit.ControlSend(strWindow, "", strControl, strKeys, nMode);
                Trace.WriteLine("Sent Keys: " + strKeys);
            }

            for (int i = 0; i < (nSleep / 100); i++)
            {
                Application.DoEvents();
                Thread.Sleep(100);
            }
        }

        private void Click(string strButton, int nNumClicks, int nX, int nY, string strControl, int nSleep, string strWindow)
        {
            autoit.ControlClick(strWindow, "", strControl, strButton, nNumClicks, nX, nY);

            for (int i = 0; i < (nSleep / 100); i++)
            {
                Application.DoEvents();
                Thread.Sleep(100);
            }
        }


The first step that must be done is to determine the required parameters like as title, text, control, etc..
You can see the images below.



Parameters :
Title : "[CLASS:Notepad]" or "Untitled - Notepad"
Text : ""
Control : Edit1
nX : 78
nY : 53
private void runButton_Click(object sender, EventArgs e)
        {
            //check if notepad is already exist
            if (autoit.WinExists("[CLASS:Notepad]", "") == 1)
            {
                //notepad closed
                autoit.WinKill("[CLASS:Notepad]", "");
            }
            //execute notepad.exe
            autoit.Run("Notepad.exe", "", 1);
            //wait for max 25 seconds
            autoit.WinWaitActive("[CLASS:Notepad]", "", 25);
            //check if notepad doesn't exist
            if (autoit.WinExists("[CLASS:Notepad]", "") == 0)
            {
                MessageBox.Show("Notepad didn't opened");
            }
            else
            {
                //activate the notepad
                //or set notepad into front

                autoit.WinActivate("[CLASS:Notepad]", "");
            }
            //send some text into text area
            string strText = "autoitsourcecode.blogspot.com";
            Type(strText, 0, "Edit1", true, 500, "[CLASS:Notepad]");
            //try to copy / paste

            //send CTRL+ a
            Type("^a", 0, "Edit1", true, 1000, "[CLASS:Notepad]");

            //send CTRL + c (Copy)
            Type("^c", 0, "Edit1", true, 1000, "[CLASS:Notepad]");

            //send CTRL + v (paste)
            Type("^v", 0, "Edit1", true, 1000, "[CLASS:Notepad]");

            //send CTRL + v (paste)
            Type("^v", 0, "Edit1", true, 1000, "[CLASS:Notepad]");

            //send CTRL + v (paste)
            Type("^v", 0, "Edit1", true, 1000, "[CLASS:Notepad]");
            //send CTRL + v (paste)
             Type("^v", 0, "Edit1", true, 1000, "[CLASS:Notepad]");
            //save the file
            //send key alt + f + a

            Type("!fa", 0, "Edit1", true, 500, "[CLASS:Notepad]");
            //wait the "save as" win dialog is opened until 25 seconds
            autoit.WinWaitActive("Save As", "", 25);
            //check if didn't open
            if (autoit.WinExists("Save As", "") == 0)
            {
                MessageBox.Show("The can't saved");
            }


This is images Save As window info



Parameters :
Title : "Save As"
Text : ""
Control : Edit1
nX : 109
nY : 8
            //send key directory folder
            Type(@"C:\autoitDemo.txt", 0, "Edit1", true, 1000, "Save As");
            //check the files
            if (File.Exists(@"C:\autoitDemo.txt"))
                File.Delete(@"C:\autoitDemo.txt");
The image for click Save button


Parameters :
Title : "Save As"
Text : ""
Control : Edit1
nX : 46
nY :13

            //click button save
            Click("left", 1, 42, 15, "Button1", 1000, "Save As");
            //check if notepad is already exist
            if (autoit.WinExists("[CLASS:Notepad]", "") == 1)
            {
                //notepad closed
                autoit.WinKill("[CLASS:Notepad]", "");
            }
        }

Download Full Source Code