Powered By Blogger

C#SHARP ANSWER

Friday, June 24, 2011

extracting all .jpg images from a folder

trying to extract all the images from a folder then follow up the following code and extract all the .jpg images from a folder

 String[] athar = Directory.GetFiles(@"D:\\", "*.JPG");
        PictureBox[] pb = new PictureBox[300];

int j = 100, l = 0,k=0;
    for (k=0; k <300; k++)
    {
        pb[k] = new PictureBox();
        if (k % 5 == 0)
        {
            j += 200;
            l = 0;
        }
        pb[k].Location = new Point((l * 190) + 200, j);
        pb[k].Size = new Size(150, 100);
        pb[k].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
        pb[k].BackColor = Color.Black;
        pb[k].BorderStyle = BorderStyle.FixedSingle;
        pb[k].Image = Image.FromFile(athar[k]);
        pb[k].Visible = true;
        this.Controls.Add(pb[k]);
        pb[k].Cursor = System.Windows.Forms.Cursors.Hand;

        // Panel1.Controls.Add(pb[i]);

        pb[k].BringToFront();
      l++;
    }

creating thumbnail of a image

Feeling that you website is taking much time to load due to heavy size images then i have a solution to make your website load faster by just creating thumbnail of those images you want to add to your website.
C# code to create thumbnail of image is as follows

            string tostore="D:\\DSCF2088";
            int ImageHeight=200,n=0;
            foreach (string at in athar)
            {
                System.Drawing.Image i = System.Drawing.Image.FromFile(at);
                i.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                i.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                System.Drawing.Image th = i.GetThumbnailImage
                                    (
                                    ImageHeight * i.Width / i.Height,
                                    ImageHeight,
                                    new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),
                                    IntPtr.Zero
                                    );
                i.Dispose();
                EncoderParameters ep = new EncoderParameters(1);
                ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)80);
                ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
                th.Save(tostore+n+".jpg", ici, ep);
                th.Dispose();
                n++;
            }

Wednesday, June 15, 2011

c# code to copy the file

using System;
using System.IO;

class FileCopy
{
  public static void Main() 
  {
    string sourceFile = @"C:\SourceFile.txt";
    string destinationFile = @"C:\DestinationFile.txt";

    //Attempt file copy
    try 
    {
      //Delete destinationFile for overwrite,
      //causes exception if already exists.
      File.Delete(destinationFile);

      File.Copy(sourceFile, destinationFile);
       
      //Successful if the method gets this far without causing an exception
      Console.WriteLine("Copy completed.");
    } 

    //If the file copy fails then catch will gain control of the method
    catch (Exception exc)
    {
      Console.WriteLine(exc.Message);
    }

    Console.WriteLine("\nPress Enter to Continue:");
    Console.Read();
  }
}

Saturday, June 4, 2011

What c# Brings to the table


        given the .NET is such a radical departure from the current thoughts of the day,Microsoft has developed a new programming language(C#) specifically for this new platform. C# is programming language that looks very similar to syntax of java. for example like java a c# class definition is contained within a single-source code file (*cs) rather than c++ centric view of splitting a class definition into discrete header(*h) and implementation (*cpp) files. however ,to call c# a java rip-off is inaccurate. both c# and java are based on the syntactical construct of c++.just as java is in many way a cleaned version of java-after all they are all in the same family of languages.
 

Friday, June 3, 2011

Features of C# Language


No pointers required ! C# programs typically have no need for
direct pointer manipulation.
 Automatic memory management.
 Formal syntactic constructs for enumerated structures and class
properties.
The C++ like ability to overload operators
Full support for interface based programming techniques
Full support for aspect based programming technique via
attribute..