Creating Torrents

 1         // 'path' is the location of the file/folder which is going to be converted
 2         // to a torrent. 'savePath' is where the .torrent file will be saved.
 3         void CreateTorrent(string path, string savePath)
 4         {
 5             // The class used for creating the torrent
 6             TorrentCreator c = new TorrentCreator();
 7 
 8             // Add one tier which contains two trackers
 9             List<string> tier = new List<string>();
10             tier.Add("http://www.example.com/announce");
11             tier.Add("http://backup.example.com/announce");
12 
13             c.Announces.Add(tier);
14             c.Comment = "This is the comment";
15             c.CreatedBy = "Alan using " + VersionInfo.ClientVersion;
16             c.Publisher = "www.homepage.com";
17 
18             // Set the torrent as private so it will not use DHT or peer exchange
19             c.Private = true;
20 
21             // Path can be either a directory *or* a file.
22             c.Path = path;
23 
24             // Every time a piece has been hashed, this event will fire. It is an
25             // asynchronous event, so you have to handle threading yourself.
26             c.Hashed += delegate (object o, TorrentCreatorEventArgs e) {
27                 Console.WriteLine("Current File is {0}% hashed", e.FileCompletion);
28                 Console.WriteLine("Overall {0}% hashed", e.OverallCompletion);
29                 Console.WriteLine("Total data to hash: {0}", e.OverallSize);
30             };
31 
32             // Create the torrent file and save it to the specified path
33             c.Create(save_path);
34         }