Sunday 31 May 2015

Storing & Retrieving Dataset from Viewstate

Storing 
 Viewstate["datasetname"] = ds;
For Retrieving 
 ds = (Dataset) Viewstate["datasetname"];

Control 'MainContent_GridView1' of type 'GridView' must be placed inside a form tag with runat=server

public override void VerifyRenderingInServerForm(Control control)
{
   //
}

tell the compiler that the control is rendered explicitly by overriding the VerifyRenderingInServerForm event.

Wednesday 20 May 2015

bat file to run multiple Skype account if one is already open

For 32-bit operating systems:

CD\
CD C:\Program Files\Skype\Phone\

Skype.exe /secondary

For 64-bit operating systems:

CD\
CD C:\Program Files (x86)\Skype\Phone\

Skype.exe /secondary  

Tuesday 12 May 2015

Class for Extracting Each Images from a Pdf file using PDF sharp.!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
//using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using System.Text;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Advanced;


namespace OfficeConverter
{
    public class Pdf2Image
    {
        //http://www.pdfsharp.net/wiki/ExportImages-sample.ashx?Code=1
        // Retrive PageCount of a multi-page tiff image
        // Fuction will accept pdf file with full path and split the file in to
        //individual files as per pages and create a folder i folder name.


        public int ExtractPagestoJpeg(string sourcePdfPath, string DestinationFolder)
        {

            int i = 0;
            string filename = sourcePdfPath;


            PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(filename);



            int imageCount = 0;

            // Iterate pages

            foreach (PdfPage page in document.Pages)
            {

                // Get resources dictionary

                PdfDictionary resources = page.Elements.GetDictionary("/Resources");

                if (resources != null)
                {

                    // Get external objects dictionary

                    PdfDictionary xObjects = resources.Elements.GetDictionary("/XObject");

                    if (xObjects != null)
                    {
                        ICollection<PdfSharp.Pdf.PdfItem> items = xObjects.Elements.Values;

                        // Iterate references to external objects
                        int z = 0;
                        foreach (PdfItem item in items)
                        {
                            z = 1;
                            PdfReference reference = item as PdfReference;

                            if (reference != null)
                            {

                                PdfDictionary xObject = reference.Value as PdfDictionary;

                                // Is external object an image?

                                if (xObject != null && xObject.Elements.GetString("/Subtype") == "/Image")
                                {

                                    ExportImage(xObject, ref imageCount, DestinationFolder, z);
                                    z++;
                                }

                            }

                        }

                    }

                }

            }
            return i;

        }

        static void ExportImage(PdfDictionary image, ref int count, string DestinationFolder, int z)
        {

            string filter = image.Elements.GetName("/Filter");

            switch (filter)
            {

                case "/DCTDecode":

                    ExportJpegImage(image, ref count, DestinationFolder, z);

                    break;



                case "/FlateDecode":
                    ExportAsPngImage(image, ref count);


                    break;

            }

        }

        static void ExportJpegImage(PdfDictionary image, ref int count, string DestinationFolder, int z)
        {

            // Fortunately JPEG has native support in PDF and exporting an image is just writing the stream to a file.

            byte[] stream = image.Stream.Value;


            FileStream fs = new FileStream(String.Format(DestinationFolder + "//" + z + ".jpeg", count++), FileMode.Create, FileAccess.Write);

            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(stream);

            bw.Close();

        }

        static void ExportAsPngImage(PdfDictionary image, ref int count)
        {

            int width = image.Elements.GetInteger(PdfImage.Keys.Width);

            int height = image.Elements.GetInteger(PdfImage.Keys.Height);

            int bitsPerComponent = image.Elements.GetInteger(PdfImage.Keys.BitsPerComponent);


            // TODO: You can put the code here that converts vom PDF internal image format to a Windows bitmap

            // and use GDI+ to save it in PNG format.

            // It is the work of a day or two for the most important formats. Take a look at the file

            // PdfSharp.Pdf.Advanced/PdfImage.cs to see how we create the PDF image formats.

            // We don't need that feature at the moment and therefore will not implement it.

            // If you write the code for exporting images I would be pleased to publish it in a future release

            // of PDFsharp.

        }
    }
}

Friday 8 May 2015

Header N Footer For Taking Scripts

Stored Procedures
********************

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Template_GetSubDropdown')
BEGIN
DROP  Procedure  Template_GetSubDropdown
PRINT 'Template_GetSubDropdown DROPPED'
END
GO


GO
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Template_GetSubDropdown')
BEGIN
PRINT 'Template_GetSubDropdown CREATED.'
END
GO


Scalar-Valued Functions
**************************

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'FN' AND name = 'FN_GetDeleteOptionForTemplate')
BEGIN
DROP  FUNCTION  FN_GetDeleteOptionForTemplate
PRINT 'FN_GetDeleteOptionForTemplate DROPPED'
END
GO


GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'FN' AND name = 'FN_GetDeleteOptionForTemplate')
BEGIN
PRINT 'FN_GetDeleteOptionForTemplate CREATED.'
END
GO


Table-Valued Functions
**********************

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'TF' AND name = 'FN_GettemplateIdFromProjectType')
BEGIN
DROP  FUNCTION  FN_GettemplateIdFromProjectType
PRINT 'FN_GettemplateIdFromProjectType DROPPED'
END
GO


GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'TF' AND name = 'FN_GettemplateIdFromProjectType')
BEGIN
PRINT 'FN_GettemplateIdFromProjectType CREATED.'
END

GO

Thursday 7 May 2015

How to Create an application for "Text to speech" using System.Speech.Synthesis in C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.IO;

namespace WindowsFormsApplication6
{
    public partial class Reader : Form
    {
        public SpeechSynthesizer synthesizer;
        public string SpeechText = string.Empty;
        public Reader()
        {
            InitializeComponent();
        }

        private void VoiceSlelection()
        {
            try
            {
                if (ddlvoice.SelectedItem.ToString() == "Female Voice")
                {
                    synthesizer.SelectVoiceByHints(VoiceGender.Female);
                }
                else if (ddlvoice.SelectedItem.ToString() == "Male Voice")
                {
                    synthesizer.SelectVoiceByHints(VoiceGender.Male);
                }

            }
            catch
            {

            }

        }
        private void ToolBarButtonStyle(Button btn, bool value)
        {
            btn.Enabled = value;
        }
        private void btnread_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtdoc.Text != "")
                {

                    synthesizer = new SpeechSynthesizer();
                    VoiceSlelection();
                    ddlvoice.Enabled = false;

                   // synthesizer.Volume = 100;  // 0...100
                   // synthesizer.Rate = -2;     // -10...10
                    SpeechText = txtdoc.Text.Trim();
                    // Synchronous
                    //synthesizer.Speak("Hello World");

                    // Asynchronous
                    synthesizer.SpeakAsync(SpeechText);
                    lblmessage.Text = "SPEAKING";
                    synthesizer.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(reader_SpeakCompleted);
                }
                else
                {
                    MessageBox.Show("Please enter text to read", "Message", MessageBoxButtons.OK);
                }
            }
            catch
            {

            }
        }

        void reader_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
        {
            lblmessage.Text = "IDLE";
            idle();
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                DialogResult result = fbd.ShowDialog();

                SpeechSynthesizer Savesynthesizer = new SpeechSynthesizer();

                Savesynthesizer.SetOutputToWaveFile(fbd.SelectedPath + "\\Speech.wav");

                Savesynthesizer.Dispose();
            }
            catch
            {

            }
        }

        private void btnpause_Click(object sender, EventArgs e)
        {
            try
            {
                if (synthesizer != null)
                {
                    if (synthesizer.State == SynthesizerState.Speaking)
                    {
                        synthesizer.Pause();
                        lblmessage.Text = "PAUSED";
                        idle();
                    }
                }
            }
            catch
            {

            }
        }

        private void btnplay_Click(object sender, EventArgs e)
        {
            try
            {
                if (synthesizer != null)
                {
                    if (synthesizer.State == SynthesizerState.Paused)
                    {
                        synthesizer.Resume();
                        lblmessage.Text = "SPEAKING";
                    }

                }
            }
            catch
            {

            }
        }

        private void btnstop_Click(object sender, EventArgs e)
        {
            try
            {
                if (synthesizer != null)
                {
                    synthesizer.SpeakAsyncCancelAll();
                    synthesizer.Dispose();


                    lblmessage.Text = "IDLE";
                    idle();
                    // MessageBox.Show("Goodbye");
                    // Application.Exit();
                }
            }
            catch
            {

            }
        }

        private void btnReadAgain_Click(object sender, EventArgs e)
        {
            try
            {
                if (synthesizer != null)
                {
                    lblmessage.Text = "IDLE";
                    txtdoc.Text = "";
                    synthesizer.Dispose();
                    idle();
                }
            }
            catch
            {

            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                ddlvoice.SelectedIndex = 0;
                lblmessage.Text = "Copy Paste the text in the plain and click on Read button";
            }
            catch
            {

            }
        }

        private void idle()
        {
            if (lblmessage.Text.ToString() == "IDLE")
            {
                ddlvoice.Enabled = true;
            }
            else
            {
                ddlvoice.Enabled = false;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
       
            MessageBox.Show("This App is for Lazy ppl like me ;) Thanks Gokuldas.Palapatta","Message", MessageBoxButtons.OK);
        }
 
    }
}

Tuesday 5 May 2015

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.


How to check the collation

  SELECT
    col.name, col.collation_name
FROM
    sys.columns col
WHERE
    object_id = OBJECT_ID('User')


Solution:

SELECT ID
FROM UserMapping
INNER JOIN User
WHERE UserId COLLATE DATABASE_DEFAULT
= UserMappingUserID COLLATE DATABASE_DEFAULT