Shell Programming Using C# (contd) Creating Shell Extended Application for File Operations

Shell Programming Using C# (contd) Creating Shell Extended Application for File Operations

Creating Shell Extended Application for File Operations 

Second Section deals with the shell concept programming towards creating file operation.The file operations enables the user to manage files using the Shell applications. User can launch any application in one click. They can open an image file copy files to other files, copy folders to other folders, move folders to othe folders,move files to other files, and they can add the specific file the recent list and also can clear the recent list.
In this section the shell concept includes a function used to create an application in which when a file is selected and opened opens the appropriate editor or launches the application.
For example:
When we select a bmp file and open it , it will automatically opens in the editor or launched in the applications like Image Viewer.
For doing these operation Shell needs some parameters passed from the UI to the Shell.The Parameters are Verbs like(Open , Edit , Delete , Copy , Move) along with file names.
To perform these operations we need to have a specific function which could take care of all the concepts and operations. So we create a Shell Execute Function to enable the File Operations.
The Shell Execute class is responsible for all the File Operations like open, edit, delete, move and copy. The function Shell Exexute would find which process has to be performed and when it needs to be called.
The Files specified will also be added to the recent list when we add the function to add the file to recent list using the Shell Programming.

public enum FileOperationsDem0{

FILE_MOVE = 0x0001, // Move the files specified in pFrom to the location specified in pTo.

FILE_COPY = 0x0002, // Copy the files specified in the pFrom member to the location specified

// in the pTo member.

FILE_DELETE = 0x0003, // Delete the files specified in pFrom.

FILE_RENAME = 0x0004 // Rename the file specified in pFrom. You cannot use this flag to rename

// multiple files with a single function call. Use FO_MOVE instead.

}

[Flags]

public enum ShellFileOperationFlags

{

FILE_MULTIDESTFILES = 0x0001, // The pTo member specifies multiple destination files (one for

// each source file) rather than one directory where all source

// files are to be deposited.

FILE_CONFIRMMOUSE = 0x0002, // Not currently used.

FILE_SILENT = 0x0004, // Do not display a progress dialog box.

FILE_RENAMEONCOLLISION = 0x0008, // Give the file being operated on a new name in a move, copy, or

// rename operation if a file with the target name already exists.

FILE_NOCONFIRMATION = 0x0010, // Respond with "Yes to All" for any dialog box that is displayed.

FILE_WANTMAPPINGHANDLE = 0x0020, // If FOF_RENAMEONCOLLISION is specified and any files were renamed,

// assign a name mapping object containing their old and new names

// to the hNameMappings member.

FILE_ALLOWUNDO = 0x0040, // Preserve Undo information, if possible. If pFrom does not

// contain fully qualified path and file names, this flag is ignored.

FILE_FILESONLY = 0x0080, // Perform the operation on files only if a wildcard file

// name (*.*) is specified.

FILE_SIMPLEPROGRESS = 0x0100, // Display a progress dialog box but do not show the file names.

FILE_NOCONFIRMMKDIR = 0x0200, // Do not confirm the creation of a new directory if the operation

// requires one to be created.

FILE_NOERRORUI = 0x0400, // Do not display a user interface if an error occurs.

FILE_NOCOPYSECURITYATTRIBS = 0x0800, // Do not copy the security attributes of the file.

FILE_NORECURSION = 0x1000, // Only operate in the local directory. Don't operate recursively

// into subdirectories.

FILE_NO_CONNECTED_ELEMENTS = 0x2000, // Do not move connected files as a group. Only move the

// specified files.

FILE_WANTNUKEWARNING = 0x4000, // Send a warning if a file is being destroyed during a delete

// operation rather than recycled. This flag partially

// overrides FOF_NOCONFIRMATION.

FILE_NORECURSEREPARSE = 0x8000 // Treat reparse points as objects, not containers.

}

 

  

The above figure shows the Operations that could be done using the Shell.

Open EXE:

This operation enables the file specified in the textbox to open. The Process is a shell based process which checks the files or folders and opens them. ShellExecParam function enables the process and opens the selected files. The Parameters are passed to the function and the process executes

Show BMP:

This operation enables the BMP or JPEG files to be opened in the Image Viewer. The ShellExecParam function enables the process and opens the selected image. The Parameter are passed to the function and executed.

This operation is same as Show BMP it opens the image in the editor enabling the editing of the images.The parameters are all passed to the function including file name.

Find in folder:

This operation enables the Find process in a specified foler. It displays the Search for the files Window and selects the specified file path in it.

Explore folder:

This Operation enalbes the exploring the folders specified. This Opens the entire folder and all the sub folders are displayed.

Copy , Move , Delete Files

The File names (Source and the Destination) are given for the Copy and Move operations. The Copy file copies entire file to another file having the backup of the source.

The Move File moves entire file to another without backup.

The Delete Files removes the specified file from the folder specified.

The Folders are also be used for Move, Copy , Delete Operations.

Add Recent Files

The Add recent files is the process of adding the Recently Opened files to the Recent Documents. It has the unique process to add the Recent files.

Clear Recent Files.This Process clears the recent files added.


This figure shows the Explore Foler option which opens the specified folder and all the sub folders in it are shown in the right pane.

The Figure 2.3 shows the file open process , in which specified file is opened and shown with the appropriate eidtor

Figure 2.4 shows the Image file opend in the Image Viewer.

Figure 2.5 shows the image files opened in appropriate file when the image file name is given.

Figure 2.6 shows the Find folder Process which opens the search window for the specified folder or directory. The process uses the Shell commands to display the results.

Conclusion for Second Section

In this section we discussed about the File Operations that can be done and customized using Shell in C#.

 

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.