Friday, 23 October 2015

Working with FileObject in JavaScript

Normally, we do follow all file operation at Server Level.

Sometimes, we got requirement from Clients to save file at local machine, create folder at Specific path, delete temporary file or folder, etc..

We can use FileSystem Object which is provided by IE.
It will work in Internet Explorer Only. 

We can not use the same feature for other browsers as they do not provide FileSystem Object.

There are number of methods that we can use for File Operations.

1. CreateFolder()
        Syntax: filesystemobject.CreateFolder(name)

        This method used to create a new folder at client machine. use the following code snippet to implement the same for your application.

     <script language="JScript">
      function create()
           var myObject, newfolder;
          myObject = new ActiveXObject("Scripting.FileSystemObject");
          newfolder = myObject.CreateFolder ("c:\\newtmp\\");
 <form name="myForm">
        <input type="Button" value="Click to Create New Folder" onClick='create()'>

2. CreateTextFile()

Sometimes, we need to store some data which we need to use for further operation, at that time, we create a local file at client location. for that CreateTextFile is useful which helps to create a file at client machine.

    Syntax: filesystemobject.CreateTextFile(filename, overwrite)

Overwrite is a boolean value which indicates whether you want to overwrite the existing file.
use the following snippet example for more clarification.

     <script language="JScript">
      function createFile()
          var myObject, newfile;
          myObject = new ActiveXObject("Scripting.FileSystemObject");
          newfile = myObject.CreateTextFile("c:\\testing.txt", false);
     <form name="myForm">
    <input type="Button" value="Click to Create New File" onClick='createFile()'>

The same way there are many methods which is used for file operation at client side.
for more details please visit: More Methods

3. BuildPath()
4. CopyFile()
5. CopyFolder()
6. DeleteFile()
7. DeleteFolder()
8. DriveExists()
9. GetAbsolutePathName()
10. GetBaseName()
11. GetDrive()
12. Drives()
13. FileExists()
14. FolderExists()
15. GetDriveName()
16. GetExtensionName()
17. GetFile()
18. GetFileName()
19. GetFolder()
20. GetParentFolderName()
21. GetSpecialFolder()
22. MoveFile()
23. MoveFolder()
24. OpentextFile()

Wednesday, 21 October 2015

Create Library folder using C# in windows 7 or later versions

Library Sample

As you all aware that, In windows 7 Microsoft has launched Library feature in operating system. as you can see it in below image, library is visible in left pan in explorer window.

This is neither a shortcut nor folder. It is a different API.

In some ways, a library is similar to a folder. For example, when you open a library, you'll see one or more files. However, unlike a folder, a library gathers files that are stored in several locations. 

It does not store any data. It monitors folders that contain your items, and let you access and arrange the items in different ways.

you can see the feature of library from msdn

To implement the same using C# programming language, we need to use Shell API provided by microsoft as well as APICodePack.

You'll found many post which is available in C++.

After my long research and PoC, I have found an easy way to impletement the same. you can follow guidelines from here Include Library & working with Windows Library

Please follow the steps to Create a small program which may be useful for your application. 

1. Create a console application & give it a suitable name i.e. CreateLibrary.

Create Project

2. Open Package Manager Console and add reference from Nuget.

you can view reference detail from nuget. OR simply run the below command.
Install-Package WindowsAPICodePack-Shell

It will add required Shell DLL in project solution. if you check in your reference folder, two DLLs will be added.

  1. Microsoft.WindowsAPICodePack 
  2. Microsoft.WindowsAPICodePack.Shell
3. add Namespace in Program.cs file.
        using Microsoft.WindowsAPICodePack.Shell;


4. Create one method to create library using ShellLibrary class as shown below.

        public static bool CreateLibrary()
                ShellLibrary lib = new ShellLibrary("Sample", true); 
                //[you can give a different name of library which is suitable for your requirement ]
                //[true flag mentions that overwrite library if exist, and there is no issue of                               // overwriting it as it is just a pointer to folder]
                string path = "D:\\";  
                //[Path that you want to refer]
            catch (Exception)
                return false;
            return true;
Code Snipet

5. Call this method from main() function.

function call

6. Run the program. you can see the Library is created in Libraries in left pan.
New Library added

The same way you can choose your folder which you need to point in Library, give an appropriate name of Library. and use the code snippet in your program need.

You can use this as a referenceDLL, in Window Application as well as API calls.

Please note that this DLL is not signed - does not provided by Author. so you can not create signed DLL. so you can not use the same in ActiveX if you are planning to use it. Because ActiveX requires Signed DLL only.


For any queries please drop a message.

Tuesday, 21 April 2015

I'm Back !!

Hell yeah !!!

It's been long time I was away from this blog.
Now, It's time to recollect all the knowledge and start putting it down here.

So, I'd like to share what happened in this last 3 years... :)

well, nothing special. As usual Life.

I have traveled a lot in past year 2014. It was wonderful time with new and old friends, colleagues and all.

The good thing, Minesweeper is still running in a good shape,

Ahh!! Unfortunetly, I have closed my account, so I may have to rebuild the app again after creating new facebook app. Anyways. Let's go further.

I have created ChainReaction Game also which is a multiplayer game.

I have created a wesbite[] for shopping coupons and offers, which is created in MVC4, and with the help of OWIN, external authentication is handled.

I'm working on another website, named dont know when I will actually start my coding and publish it. But I have it in my mind to develop and publish to help all food-alcoholic people.

that's it for now,

see you falks.