Wednesday, December 17, 2014

Image From Web URL to Base64 String

Image are Download using Web Client and byte code pass for base64 conversion. 


using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web;
using System.Web.UI;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void convert_Click(object sender, EventArgs e)
    {
        byte[] raw;
        raw = new WebClient().DownloadData(txturl.Text);
        Context.Response.Write(CreateBase64Image(raw));
    }

    private string CreateBase64Image(byte[] fileBytes)
    {
        System.Drawing.Image streamImage;
        /* Ensure we've streamed the document out correctly before we commit to the conversion */
        using (MemoryStream ms = new MemoryStream(fileBytes))
        {
            /* Create a new image, saved as a scaled version of the original */
             streamImage = (System.Drawing.Image.FromStream(ms));
        }
        using (MemoryStream ms = new MemoryStream())
        {
            /* Convert this image back to a base64 string */
            streamImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return Convert.ToBase64String(ms.ToArray());
        }
    }

}


Return Like :

Thursday, July 24, 2014

MySQL XML Querying

DROP PROCEDURE IF EXISTS `test223`$$ CALL test223()
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `test223`()
BEGIN
 DECLARE xmlDoc TEXT;
 DECLARE i INT ;
 DECLARE coun INT;
 DECLARE child1 VARCHAR(400);
 DECLARE child2 VARCHAR(400);

 SET i =1;

 SET xmlDoc = '<Data><parent><child1>Example 1</child1><child2>Example 2</child2></parent><parent><child1>Example 3</child1><child2>Example 5</child2></parent><parent><child1>Example 5</child1><child2>Example 6</child2></parent></Data>';

 SET coun = ExtractValue(xmlDoc, 'count(/Data/parent/child1)');

 DROP TEMPORARY TABLE  IF EXISTS `parent`; 
 CREATE TEMPORARY TABLE parent (     child1 VARCHAR(400),   
                                                                              child2 VARCHAR(400) ); 


 WHILE i <= coun DO


     INSERT INTO parent
    SELECT ExtractValue(xmlDoc, '//parent[$i]/child1'), ExtractValue(xmlDoc,   '//parent[$i]/child2');

    SET i = i+1;

 END WHILE;

   SELECT * FROM  parent; 

END$$

DELIMITER ;



Response Table :

+---------------------+
| Child1      | Child2     |
|-----------|-----------|
|Example 1 |Example 2|
|-----------|-----------|
|Example 3 |Example 5|
|-----------|-----------|
|Example 5 |Example 6|
|-----------|-----------|

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...