It's not about me, it's my blog!

Author Archive

All the browsers still not support rounded corners on block elements, we wait for CSS3 to be finalized them. CurvyCorners is a free JavaScript library for creating rounded corners for HTML block elements like DIVs.

Read the rest of this entry »

In CodeProject I saw that so many newbies to log4net struggle to manage multiple log files from a one application. So I just wrote a simple article and though of sharing with you all.

www.codeproject.com/Tips/400224/Multiple-log-files-from-one-application-using-log4

In my previous post here I have explain about the recursive file and folder copy with C#. This time I want to do the same with Java. You can easily copy files and folders by using the copy(Path, Path, CopyOption) method. However, files inside a folder are not copied and you can find the new folder empty even the destination folder has some.

In the following method I did not use such APIs, instead read byte streams from the source and copied into the destination when you want to copy files and create folders when you want copy folders from source to destination.

private void recursiveCopy(File fSource, File fDest) {
     try {
          if (fSource.isDirectory()) {
          // A simple validation, if the destination is not exist then create it
               if (!fDest.exists()) {
                    fDest.mkdirs();
               }

               // Create list of files and directories on the current source
               // Note: with the recursion 'fSource' changed accordingly
               String[] fList = fSource.list();

               for (int index = 0; index < fList.length; index++) {
                    File dest = new File(fDest, fList[index]);
                    File source = new File(fSource, fList[index]);

                    // Recursion call take place here
                    recursiveCopy(source, dest);
               }
          }
          else {
               // Found a file. Copy it into the destination, which is already created in 'if' condition above

               // Open a file for read and write (copy)
               FileInputStream fInStream = new FileInputStream(fSource);
               FileOutputStream fOutStream = new FileOutputStream(fDest);

               // Read 2K at a time from the file
               byte[] buffer = new byte[2048];
               int iBytesReads;

               // In each successful read, write back to the source
               while ((iBytesReads = fInStream.read(buffer)) >= 0) {
                    fOutStream.write(buffer, 0, iBytesReads);
               }

               // Safe exit
               if (fInStream != null) {
                    fInStream.close();
               }

               if (fOutStream != null) {
                    fOutStream.close();
               }
          }
     }
     catch (Exception ex) {
          // Please handle all the relevant exceptions here
     }
}

Last week, when I am working with ontologies I came up with a requirement to update a XML using Java. I just want to modify the text of a child node of a give node in a DOM document. Only three steps you have to keep in mind,

  1. Read into the relevant node.
  2. Update the text content.
  3. Save it back to XML.

Read the rest of this entry »

I love recursion. If you want to copy files and folder into a different folder location, you have to copy files into the relevant folder in destination as similar to the source, use recursion.

In c# there is no direct way to copy files and folders into a different folder location. You have to do it manually and there are several ways to do the same. With recursion, logically what you have to do is point the correct source directory into the File.Copy operation.

/// <summary>
/// Files and folder copy recursively from source to destination.
/// </summary>
/// <param name="strSourceFolder">Source folder path</param>
/// <param name="strDestfolder">destination folder path</param>
private void RecursiveCopy(string strSourceFolder, string strDestfolder)
{
     // A validation, if the destination folder is not exists create it
     if (!System.IO.Directory.Exists(strDestfolder))
     {
          System.IO.Directory.CreateDirectory(strDestfolder);
     }

     string[] arrFiles = System.IO.Directory.GetFiles(strSourceFolder);
     foreach (string file in arrFiles)
     {
          string strFileName = System.IO.Path.GetFileName(file);
          string strFilePath = System.IO.Path.Combine(strDestfolder, strFileName);
          System.IO.File.Copy(file, strFilePath);
     }

     string[] arrDirectories = System.IO.Directory.GetDirectories(strSourceFolder);
     foreach (string directory in arrDirectories)
     {
          string strFileName = System.IO.Path.GetFileName(directory);
          string strFilePath = System.IO.Path.Combine(strDestfolder, strFileName);
          RecursiveCopy(directory, strFilePath);
     }
}

In C#, if you copy the same file into the same destination it will end up with IOException saying that the file already exist. There is no inbuilt function to handle this situation. All what you have to do is rename the file name as follows.

System.IO.FileInfo fInfo = new System.IO.FileInfo(@"C:\demo\source\temp.txt");
string strFileName = System.IO.Path.GetFileNameWithoutExtension(fInfo.Name);

// Check to see if the file exists
if (System.IO.File.Exists(@"C:\demo\destination\temp.txt"))
{
     // It does, handle the file name

     // Postfix with the current time tick. You may user your own logic if required.
     strFileName += DateTime.Now.Ticks.ToString();

     // Set back the extension
     strFileName += System.IO.Path.GetExtension(fInfo.Name);

     // Combine two paths
     string strFilePath = System.IO.Path.Combine(@"C:\demo\destination", strFileName);
     fInfo.CopyTo(strFilePath);
}
else
{
     // It does not, use the original file name
     fInfo.CopyTo(@"C:\demo\destination\temp.txt");
}
Tags: , , ,

Last evening I came up with a requirement to drag a folder path into a TextBox in one of my Windows form applications. So I just want to share it with you all through a simple example.

Drag-and-drop operations in WinForms accomplish via handling of a series of events, mostly with the DragDrop, DragEnter and DragLeave. Working with the event arguments of these events eventually you can facilitate drag and drop.

Read the rest of this entry »

You can use inheritance in WPF to create styles base on another style. For example, you can create one style for all the Button elements and create an inherited style to provide emphasis for one of the buttons.


<Style x:Name="baseStyle" TargetType="{x:Type Button}">
    <Setter Property="FontSize" Value="15" />
</Style>
<Style x:Name="inheritStyle" BasedOn="{StaticResource baseStyle}" TargetType="{x:Type Button}">
    <Setter Property="FontStyle" Value="Italic" />
</Style>

Last evening I met one of my friends younger brother who is attending a class to learn WPF. While we are discussing different pin points about WPF he told me that their lecturer gives him an assignment, which is a simple UI for a calculator. The most difficult part he found was how to make rounded buttons with use of Styles and all (they do not know about templates yet). There are no restrictions added by the lecturer. So give him few suggestions to search the web and give a try and I decide to write a post here on how to design such a UI with WPF.

Rounded buttons, a simple UI

Read the rest of this entry »

As a web developer you are always worried that how your website looks like in different browsers once you have design it. BrowserShots.org is one of the excellent open source web applications which provide developers with a view of their website design in vast array of operating systems and web browsers.

As they described themselves,

Browsershots makes screenshots of your web design in different operating systems and browsers. It is a free open-source online web application providing developers a convenient way to test their website’s browser compatibility in one place. When you submit your web address, it will be added to the job queue. A number of distributed computers will open your website in their browser. Then they will make screenshots and upload them to our central dedicated server for your review.

Read the rest of this entry »