본문 바로가기

C#(CSharp)/Etc31

Write exception log in File. private static void writeExceptionLog(Exception ex) { try { string curPath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); string filePath = curPath + "\\exceptionLog.log"; using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("Message :" + ex.Message + " " + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Da.. 2018. 5. 29.
c# memory cache private void btnGet_Click(object sender, EventArgs e) { ObjectCache cache = MemoryCache.Default; string fileContents = cache["filecontents"] as string; if (fileContents == null) { CacheItemPolicy policy = new CacheItemPolicy(); List filePaths = new List(); filePaths.Add("c:\\cache\\example.txt"); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); // Fetch the file contents. fileCon.. 2018. 5. 26.
Deleting multiple files with wildcard var dir = new DirectoryInfo(directoryPath); foreach (var file in dir.EnumerateFiles("f*.txt")) { file.Delete(); }SOURCE : https://stackoverflow.com/questions/8807209/deleting-multiple-files-with-wildcard?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa 2018. 5. 17.
How to crop an image using C#? static Bitmap LoadImage() { return (Bitmap)Bitmap.FromFile( @"e:\Tests\d_bigImage.bmp" ); // here is large image 9222x9222 pixels and 95.96 dpi resolutions } static void TestBigImagePartDrawing() { using( var absentRectangleImage = LoadImage() ) { using( var currentTile = new Bitmap( 256, 256 ) ) { currentTile.SetResolution(absentRectangleImage.HorizontalResolution, absentRectangleImage.Vertical.. 2018. 5. 9.