Use C#winform to write a simple batch empty file contents and delete files of the gadget

Source: Internet
Author: User

with C#winform write a simple gadget for bulk emptying of file contents and deleting files

This article describes a small project that is simply not simple enough. To do this project, there are the following purposes.

1

Of course, it's a tool to use.

2

Learn to use GitHub

For a tutorial on creating a project with VS2013 and adding it to GitHub, see (http://www.admin10000.com/document/4004.html). To put it simply, create a project with VS, then create a RESPO (code-managed project for this project) on the GitHub site, write down the address (https://*.git), and then synchronize the code to the server with the "commit" and "Sync" buttons.

This gadget I named Filewiper, whose GitHub address is (https://github.com/bitzhuwei/FileWiper.git), welcome to the discussion.

Using GitHub

There is a warehouse, called Repo A. If you want to contribute to the code, first fork this repo, so in your GitHub account has a repo A2,. Then you work under this A2, Commit,push and so on. Then you want the original warehouse repo A to merge your work, you can launch a pull request on GitHub, which means request repo A's owner to merge branches from your A2. If it is approved and formally merged, then you contribute to project A.

Empty file contents

Just open the file and overwrite the original content.

public static void wipefilecontent (string filename)

{

using (var stream =

New System.IO. StreamWriter(filename, false))

{

Stream. Write ("http://bitzhuwei.cnblogs.com");

}

}

Register to the System right-click menu

Register with the RegistryKey.

The program path is followed by a " %1" so that at startup, the args parameter in the main function contains the selected file path (or folder path).

1         Private voidBtnregister_click (Objectsender, EventArgs e)2         {3             //Add a custom right-click menu to all types of files4             {5                 varItemName ="Wipe Content";6                 varAssociatedprogramfullpath = This. GetType (). assembly.location;7                 //Create item: Shell8RegistryKey Shellkey = Registry.ClassesRoot.OpenSubKey (@"*\shell",true);9                 if(Shellkey = =NULL)Ten                 { OneShellkey = Registry.ClassesRoot.CreateSubKey (@"*\shell"); A                 } -  -                 //Create Item: Right-click the menu name displayed theRegistryKey Rightcommondkey =Shellkey.createsubkey (itemname); -RegistryKey Associatedprogramkey = Rightcommondkey.createsubkey ("Command"); -  -                 //Create default value: Associated program +Associatedprogramkey.setvalue (string. Empty, Associatedprogramfullpath +"%1"); -  +                 //flush to disk and free resources A associatedprogramkey.close (); at rightcommondkey.close (); - shellkey.close (); -             } -  -             //Add a custom right-click menu to all Folders -             { in                 varItemName ="Wipe Directory"; -                 varAssociatedprogramfullpath = This. GetType (). assembly.location; to                 //Create item: Shell +RegistryKey Shellkey = Registry.ClassesRoot.OpenSubKey (@"Directory\shell",true); -                 if(Shellkey = =NULL) the                 { *Shellkey = Registry.ClassesRoot.CreateSubKey (@"*\shell"); $                 }Panax Notoginseng  -                 //Create Item: Right-click the menu name displayed theRegistryKey Rightcommondkey =Shellkey.createsubkey (itemname); +RegistryKey Associatedprogramkey = Rightcommondkey.createsubkey ("Command"); A  the                 //Create default value: Associated program +Associatedprogramkey.setvalue ("", Associatedprogramfullpath +"%1"); -  $  $                 //flush to disk and free resources - associatedprogramkey.close (); - rightcommondkey.close (); the shellkey.close (); -             }Wuyi}
register to the system right-click menu

Unregister System Right-click menu

Still implemented with RegistryKey.

1         Private voidBtnunregister_click (Objectsender, EventArgs e)2         {3             //Delete a custom right-click menu for all types of files4             {5                 varItemName ="Wipe Content";6                 varAssociatedprogramfullpath = This. GetType (). assembly.location;7                 //Create item: Shell8RegistryKey Shellkey = Registry.ClassesRoot.OpenSubKey (@"*\shell",true);9                 if(shellkey!=NULL)Ten                 { OneShellkey.deletesubkeytree (ItemName,false); A                 } -  -                 //flush to disk and free resources the shellkey.close (); -             } -  -             //to delete a custom right-click menu for all folders +             { -                 varItemName ="Wipe Directory"; +                 varAssociatedprogramfullpath = This. GetType (). assembly.location; A                 //Create item: Shell atRegistryKey Shellkey = Registry.ClassesRoot.OpenSubKey (@"Directory\shell",true); -                 if(Shellkey! =NULL) -                 { -Shellkey.deletesubkeytree (ItemName,false); -                 } -  in                 //flush to disk and free resources - shellkey.close (); to             } +}
Unregister System Right-click menu

Welcome to the project of GitHub on the attention (HTTPS://GITHUB.COM/BITZHUWEI/FILEWIPER.GIT)!

Use C#winform to write a simple batch empty file contents and delete files of the gadget

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.