Thursday, September 27, 2012

Create thumbnail using c#



private void CreateThumbnail(string imgPath)
{
  try
  {
     Image photoImg = Image.FromFile(imgPath);
     Image thumbPhoto = photoImg.GetThumbnailImage(200,150,null,new System.IntPtr());
     thumbPhoto.Save(@"C:\aaa.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
   }
   catch (Exception exp)
   {
      MessageBox.Show("Select a valid photo!");
      return;
    }        
 }

Monday, April 2, 2012

How to refresh desktop using c# ?

Code :

[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);

public static void Refresher()
{
    // Refresh the desktop
    SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
}

Monday, February 27, 2012

How to extract custom animation details from ppt using c# ?

 The code shown below extracts custom animation detais like type of animation , duration , animation     order  etc



Wednesday, February 22, 2012

How to open a file from C# ?


This example demonstrates how to open file with an associated program. It shows, 
how to open a file and how to open url address in a default web browser.In c# 
files are opened using Process.Start method .


// open a file
System.Diagnostics.Process.Start(@"c:\letter.pdf");


//Open a URL in default browser
System.Diagnostics.Process.Start("http://snippets4you.blogspot.com");


Saturday, February 18, 2012

How to call C# com from Java Script ?

This code snippets helps you to create a c# com and call fuction in c# com from javascript code .Add a reference runtime.InteropServices.Note that this code only works with internet explorer.

C# COM : 


using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TestCOM
{
   
    [Guid("F7B3192E-8B84-4cf0-9162-95166783299A")]
    public interface COM_Interface
    {
      int disp(int aa);
    }

    [Guid("879A7994-1FE9-4379-8F84-C135B59B5C4B"),
    InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface COM_Events
    {

    }
   
    [Guid("E723167E-2244-4c9d-9681-F2E2108E49D3"),
    ClassInterface(ClassInterfaceType.None),
    ComSourceInterfaces(typeof(COM_Events))]                                                                  
    public class COM_Class : COM_Interface
    {
        public int disp(int aa)
        {
            return aa + 2;

        }
    }
}

Java script code :


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> CSHARP COM TEST </TITLE>
<script type='text/javascript' language='javascript'>

function comFunction()
{

 try
 {
   var myobject;
   myobject = new ActiveXObject("TestCOM.COM_Class");
   alert(myobject.disp(2)); //  Call DLL function here.
 }
 catch(e)
 {
  alert(e.message);
 }

}

</SCRIPT></HEAD>
<BODY>
<INPUT TYPE=button value=DLL onClick="comFunction()">
<br>
</BODY>
</HTML>

Wednesday, February 8, 2012

How do I send mail using C# ?


The following example demonstrates sending a simple text email : 


private void buttonX1_Click(object sender, EventArgs e)
{
    string strFrom, strTo,strFeedback;
    try
    {
      System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
               
      strFrom = textBoxX2.Text;
      strFeedback = richTextBox1.Text;
      objMailMessage.To.Add("jakesully25@gmail.com");
      objMailMessage.From = new System.Net.Mail.MailAddress(strFrom);

      objMailMessage.Subject = "HTML5Point";
      objMailMessage.Body = strFrom+" : "+strFeedback;
      objMailMessage.Priority = System.Net.Mail.MailPriority.High;
      System.Net.Mail.SmtpClient objSmtpClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
      objSmtpClient.EnableSsl = true;
      objSmtpClient.Credentials = new System.Net.NetworkCredential("jakesully25@gmail.com","server123");
      objSmtpClient.Send(objMailMessage);
      MessageBox.Show("Feedback Sent");
    }
    catch (Exception ex)
    {
      MessageBox.Show(ex.ToString());
    }
}

Note : Add reference System.Net.dll

Saturday, January 28, 2012

Reading & Writing registry key using C#


Reading registry key :


try
{
    RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
    if (registry != null)
   {
      MessageBox.Show(registry.GetValue("myValue").ToString());
      registry.Close();
    }
}
catch (Exception ex)
{
   MessageBox.Show (ex.ToString());
}

Writing registry key :



try
{
RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
if (registry != null)
{
registry.SetValue("myValue", "myReturnValue");
registry.Close();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}