Monday, 7 April 2014

Reading XML file - PHP

 

The easiest and simplest way to read XML file is using SimpleXML.

 

We'll consider a simple XML file test.xml with the following nodes and values.


<!-- Test.xml --> 
<root>
   <node1>Hello</node1>
   <node2>World</node2>
    <node3>This is simple Example of Parsing XML files </node3>
<root>  
 


 Loading a XML file

$xml=simplexml_load_file("filename");

Parsing a Node value 

$node=$xml->node_name;
  

 Example to demonstrate the usage of simpleXML


<?php
$xml=simplexml_load_file("test.xml");
echo $xml ->node3;
 echo '<br/>';
foreach($xml->children() as $child)   // children() get all the child nodes in the XML file.
{
      echo 'Node_name: '.$child ->getName().'   ';      // displays the node_name.
     echo 'Node_value: '.$child.'<br/>';   // displays the node value.
}
?>  




Output will be displayed as follows


This is a simple example of parsing XML files
Node_name: node1 Node_value: Hello
Node_name: node2 Node_value: World
Node_name: node3 Node_value: This is a simple example of parsing XML files 











Nodes having nested nodes can be parsed using the above method by using foreach loop. 

for more Details refer
  1. http://www.w3schools.com/php/php_xml_simplexml.asp 
  2. http://www.php.net/manual/en/simplexml.examples-basic.php  
  3. http://www.php.net/manual/en/ref.xml.php 

Difference between 2 Dates - Javascript

This Script finds the difference between 2 dates. The result is Days Count.

Date Object. 

Initializing Dates
new Date() // current date and time
new Date(milliseconds) //milliseconds since 1970/01/01
new Date(dateString) // mm/dd/yyyy format
new Date(year, month, day, hours, minutes, seconds, milliseconds)

example 

   Difference between 04/04/2014 and 04/08/2014 is 1.

Code Block

 

<html>
<head>
<script type="text/javascript">
    function getDateDifference()
    {
        var date1 = new Date("20/04/2014");
        var now = new Date();
        var timeDiff = (date1.getTime() -now.getTime());  // gets the timeDifference in milliseconds.
        /* Converts the TimeDifference to Total no of days  
            3600- Time for 1 hr in secs  (60*60);
            3600*24 - Time for 1 day in secs.
            1000 * 3600*24 - Time  for 1 day in milliseconds.
           The Math.ceil(x) function returns the smallest integer greater than or equal to a number "x".
      */
             diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
        alert(diffDays);
    }
</script>
</head>
    <body>      
        <script>getDateDifference();</script>
    </body>
</html>


References

  1. http://www.w3schools.com/js/js_obj_date.asp

Sunday, 6 April 2014

Including multiple PHP files.

Use of Including files.

  • Including multiple PHP files helps Maintainability
  • Huge blocks of code can be split into small useful blocks which can be included wherever necessary.
  • Re-usability of code.

How To 

  1. Using Require.
    • Produces a fatal-error (E_COMPILE_ERROR) and stops the script if the Code fails to load the Script file.
  2. Using Include
    • Produces a warning (E_WARNING) and Resumes the script upon failure. 
Based on Requirements choose whether to use Require or Include. 
 

 Syntax :  

<?php include 'script_name.php '  ?>
<?php require 'script_name.php'  ?>

Example


<!-- test.php --> 

echo " Hello World <br/>" ;
echo "This Message is Displayed  by the Included file test.php <br/> " ;



<!-- Main.php -->
<?php 
    echo "This is Displayed from main.php <br/>";
    include "test.php";
?> 

 Output

This is Displayed from main.php
Hello World
This message is Displayed from Test.php


For more Information refer
  1. http://www.w3schools.com/php/php_includes.asp
  2. http://www.php.net/manual/en/function.include.php
 

Thursday, 3 April 2014

Creating Outlook Appointment Programmatically in C#


The first and foremost thing in creating a Appointment is to Add reference to the library, Microsoft.Office.Interop.Outlook.dll. Find how to download here.

Once done with referencing the Library to your forms application , Use the Library by adding the code,

Outlook= Using Microsoft.Office.Interop.Outlook  



Done with all these steps ?? Creating an meeting Appointment is easy !!!.

Add the Following piece of code,to create an appointment.


/// this represents the entire outlook application. 

Outlook.Application Application = new Outlook.Application();

/// Create a new appointment. 
 Outlook.AppointmentItem newAppointment =(Outlook.AppointmentItem)
                Application.CreateItem(Outlook.OlItemType.olAppointmentItem);

/// Set the Start and End date of the appointment.
 newAppointment.Start =DateTime.Now;
 newAppointment.End = DateTime.Now.AddDays(1);

/// Set the all-day event property.
newAppointment.AllDayEvent = false;

/// set the Location,Subject and Body of the Appointment.
newAppointment.Location ="TestLocation";
 newAppointment.Subject="Meeting";
 newAppointment.Body="Appointment body";

/// set the Busy status during the time period
 newAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olFree;
 newAppointment.Save();

The appointment will be saved in your calendar.
Note:- Do not Create an All day event unless necessary.


Want to send Invitee to others ??

Add the Code below 

///create Recipients for the meeting request.
Outlook.Recipients sendTo = newAppointment.Recipients; 

/// Add invitee's.
Outlook.Recipient sentInvite = null; 
sentInvite = sentTo.Add("Dave@Example.com"); // Email of the Invitee. 
// Recipient type Required.
 sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olRequired; 
sentInvite = sentTo.Add("Dave@Example.com"); // Email of the Invitee.
// Recipient type Optional
 sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olOptional;

 /// set the meeting Status.
newAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; 

///resolve the names  against your Contacts.
sentTo.ResolveAll(); 

///Send the meeting request.
 ((Outlook._AppointmentItem)newAppointment).Send(); 

Meeting invite ll be sent to the recipients.

That's it, Done !!!!  

for more details refer,