.NET のクラスライブラリが同じパスに存在する別の DLL を動的にロードするには

動的に別のDLLをロードするときのメモ。 System.Reflection.Assembly.GetExecutingAssembly().CodeBase で自身のパスが取れる。 file:\ が先頭に付くときがあるため取り除いている。 string selfDirPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); if (selfDirPath.StartsWith(“file:\")) { selfDirPath = selfDirPath.Substring(6); } System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(selfDirPath, “Another.dll”));

2011年1月14日 · Toshimitsu Takahashi

圧縮パスワード付き ZIP ファイルを生成できる DotNetZip ライブラリを C# で試してみた

DotNetZip Library - Home DotNetZip は Microsoft Public License の ZIP ライブラリ プロジェクト。 試しに C# からコマンドラインでパスワード付きZIPを作成するサンプルプログラムを書いてみた。 using System; using System.IO; using Ionic.Utils.Zip; namespace AppTest { class Program { static void Main(string[] args) { string filePath = null; string zipfile = null; string password = null; for (int i = 0; i < args.Length; i++) { if (args[i] == “-p”) { password = args[++i]; } else if (filePath == null) { filePath = args[i]; } else { zipfile = args[i]; } } if (filePath == null || zipfile == null || !File.Exists(filePath)) { if (args.Length != 2) { Console.WriteLine(“Usage WhiteMole.exe [-p password] file zipfile”); } return; } try { zipAtEncrypt(filePath, zipfile, password); } catch (ZipException) { Console.WriteLine(“Failed to compress " + filePath); } } private static void zipAtEncrypt(string filePath, string zipfile, string password) { using (ZipFile zip = new ZipFile(zipfile)) { if (password != null) zip.Password = password; zip.AddFile(filePath); zip.Save(); } } } } ...

2008年12月23日 · Toshimitsu Takahashi