Thread was being aborted exception when downloading File. Steps To Do in VB.net to avoid it

  1. Add Trigger If the control is in an Update Panel.

    <Triggers> <asp:PostBackTrigger ControlID = “rptSearchContent” /> </Triggers>

  2. Add the below line to Page Load

    Page.Form.Attributes.Add(“enctype”, “multipart/form-data”)

Advertisements

PsExec Access Denied Problem Solution

when we try to run remote programs from local system this error saying “Access Denied” may come. To overcome this, you have to add a registry key.

  1. Open RegEdit on your remote server
  2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
  3. Add a new DWORD value called LocalAccountTokenFilterPolicy
  4. Set its value to 1
  5. Reboot your remove server
  6. Try running PSExec again from your local server

You should be able to execute remote commands.

Validators in QT

Validators are the input restriction filters we can apply up on our input fields like QLineEdit. We can make validators and apply to them so that they can be made to accept only numbers, capital letters, etc..

QT have some predefined validators. Eg for int,Regular expression etc.

We can create our own validators by subclassing QValidator class.

Example: Validator for Digits 0-9

#include “QValidator.h”

//Derive from Qvalidator
class DigitValidator:public QValidator
{   

    //Validation function. Pure virtual in QValidator
    inline State validate( QString & input, int & pos ) const
    {

        //Create a regular expression for the condition
        QRegExp vRX;
        vRX.setPattern(“[^0-9]”);

       //Search for it in the input
        if(input.contains(vRX))
        {
            return QValidator::Invalid;
        }
        else
            return QValidator::Acceptable;
    }   
};

void main()
{
    QLineEdit *txtInPut;
    txtInPut->setValidator(new DigitValidator);
}

Now the txtInPut line edit  box will only accept the input if its 0-9 other characters cant be entered.

Using TinyXML2 for XML Parsing in C++

I was searching for a easy,fast and small XML Parser for my project when I came across TinyXML2. I tried it and found that its indeed an easy and clean little parser which can cater to my need excellently.

Now lets see how it works.

Setting Up

You can get it from : https://github.com/leethomason/tinyxml2

Just download it and build the files using the solution available in the folder. Then you will get Object file(tinyxml.obj) in “tinyxml2-master\tinyxml2\Win32\Release” or “tinyxml2-master\tinyxml2\Win32\Debug” depends up on which configuration you built.

You will have to link the object file in your project settings or else you will get “Unresolved external symbol errors”.

Include “tinyxml2.h” in your C++ file.

Now we are ready to Tackle XMLs.

Load and Parse XML File

Create a XMLDocument Object and call LoadFile() function. Give the file path as its parameter.

XMLDocument xmlDoc;

xmlDoc.LoadFile(“kokkachi.xml”);

Parse XML formatted string

If you have a string which contains an XML, You can parse that using XMLDocument’s parse function.

XMLDocument dxml;

//Parse the xml sxml 
int rslt = dxml.Parse(sxml.c_str());

Getting root node

You can get the root node by calling FirstChild function of XMLDocument. It will return a pointer to the XMLNode class

XMLNode *rootnode = dxml.FirstChild();

Iterating Sibling Nodes

Then to iterate the nodes in the same level call NextSibling() function of XMLNode

XMLNode SiblingNode = rootnode ->NextSibling();

Getting Child Node

To get down to the child level nodes of current node call FirstChild() function of XMLNode

ChildNode = SiblingNode ->FirstChild();

Getting Data from Nodes

To get data from nodes we need to get the xml element from the Node. XMLNode class provides ToElement() function for this operation.

XMLElement *ChildElmt = ChildNode->ToElement();

Then we can get the Tag name of the Node using Name() function of XMLElement class.

string strTagName = ChildElmt ->Name();

We can get the values of the attributes of elements using the Attribute() function by giving the attribute name as parameter.

string strAttr = ChildElmt ->Attribute("YourAttributeName");

I am using tinyxml for some time now. And I must say I love its simplicity..

why we use Virtual Destructor

A destructor is a member function of a class, which gets called when the object goes out of scope.  So we have to do  all clean ups and final steps of class destruction are to be done in destructor.

If a member function is virtual, then calling the function on an object always invokes the function as implemented by the class which is derived finally. If the method is not virtual, then the implementation corresponding to the compile-time type of the object pointer.

Eg:

Class Base
{
public:
Base(){cout<<”Base constructor”;}
~Base{cout<<”Base destructor”;}
}
 
Class Derived: public Base
{
public:
Derived(){cout<<”Derived constructor”;}
~Derived{cout<<”Derived destructor”;}
}
 
void main()
{
Base *Obj = new Derived();
delete Obj;
}

The output will be

 

Base constructor
Derived constructor
Base destructor

From the output we can see that the derived class destructor is not getting evoked. This is where virtual function comes to our aid. If we make the base class destructor as virtual.

Class Base
{
    Base(){cout<<"Base constructor";}
    virtual ~Base{cout<<"Base destructor";}
}

We will get our desired output as

Base constructor
Derived constructor
Derived destructor
Base destructor