h1. Creating Torrents h1. Creating Torrents

        // 'path' is the location of the file/folder which is going to be converted
        // to a torrent. 'savePath' is where the .torrent file will be saved.
        void CreateTorrent(string path, string savePath)
        {
            // The class used for creating the torrent
            TorrentCreator c = new TorrentCreator();
            
            // Add one tier which contains two trackers
            List tier = new List();
            tier.Add("http://www.example.com/announce");
            tier.Add("http://backup.example.com/announce");
            
            c.Announces.Add(tier);
            c.Comment = "This is the comment";
            c.CreatedBy = "Alan using " + VersionInfo.ClientVersion;
            c.Publisher = "www.homepage.com";

            // Set the torrent as private so it will not use DHT or peer exchange
            c.Private = true;

            // Path can be either a directory *or* a file.
            c.Path = path;

            // Every time a piece has been hashed, this event will fire. It is an
            // asynchronous event, so you have to handle threading yourself.
            c.Hashed += delegate (object o, TorrentCreatorEventArgs e) {
                Console.WriteLine("Current File is {0}% hashed", e.FileCompletion);
                Console.WriteLine("Overall {0}% hashed", e.OverallCompletion);
                Console.WriteLine("Total data to hash: {0}", e.OverallSize);
            };

            // Create the torrent file and save it to the specified path
            c.Create(save_path);
        }