c#-4.0

Difference between Assembly.GetExecutingAssembly() and typeof(program).Assembly

…衆ロ難τιáo~ 提交于 2020-06-24 10:57:09
问题 What is the difference between Assembly.GetExecutingAssembly() and typeof(program).Assembly ? 回答1: Assuming program is in the executing assembly, they should both return the same value. However, typeof(program).Assembly should have better performance, since Assembly.GetExecutingAssembly() does a stack walk. In a micro benchmark on my machine, the former took about 20ns, while the latter was 30x slower at about 600ns. If you control all the code I think you should always use typeof(program)

Exception.GetBaseException() returning exception with not null InnerException

匆匆过客 提交于 2020-06-12 02:04:18
问题 I've this exception of type System.AggregateException : Message = "One or more errors occurred." Source = null StackTrace = null It's InnerException is this System.Reflection.TargetInvocationException : Message = "Exception has been thrown by the target of an invocation." Source = "mscorlib" StackTrace = at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,

Regex for removing only specific special characters from string

两盒软妹~` 提交于 2020-06-11 03:04:11
问题 I'd like to write a regex that would remove the special characters on following basis: To remove white space character @ , & , ' , ( , ) , < , > or # I have written this regex which removes whitespaces successfully: string username = Regex.Replace(_username, @"\s+", ""); But I'd like to upgrade/change it so that it can remove the characters above that I mentioned. Can someone help me out with this? 回答1: string username = Regex.Replace(_username, @"(\s+|@|&|'|\(|\)|<|>|#)", ""); 回答2: use a

How To Pass Dynamically created value into another page..?

故事扮演 提交于 2020-06-09 04:55:43
问题 i am dynamically create contents and buttons into my code behind " tree.aspx.cs " page sbmainTbl.AppendFormat("<tr><td><div class=\"a\">{0}<div class=\"details\"<p id=\"p\">{1}</p><ul><li>Parent-UnitId:{2}</li><li>Address :{3}</li><li>City: {4}</li><li>EmailId: {5}</li><li>PhoneNo: {6}</li><li>FaxNo: {7}</li><li><input type=\"button\" value=\"ADD\" onclick=\"f2();\" /></li></ul></div></div></div></td></tr>", CellText(dtparent.Rows[0]["UnitName"].ToString()), CellText(dtparent.Rows[0][

File Format check while File upload in C#

让人想犯罪 __ 提交于 2020-06-03 08:22:39
问题 While File Upload i have checked the following thing if !(strExtension == ".jpg" || strExtension == ".jpeg" || strExtension == ".pdf" || strExtension == ".png") Send Error This is working fine, But i have one issue ,if someone uploads a xlsx file by just changing its extension as jpg my uploader will not obstruct it and the file will be saved which is orginally an xlsx file How do i check the file origin. without its extension. Thanks for any help 回答1: Edit: Just use Mime Detective I use byte

C# console application bring process to foreground

自闭症网瘾萝莉.ら 提交于 2020-05-29 09:10:46
问题 With the following C# console application code, I am able to run the process in background using Jenkins. But now I want to see this process in foreground. What wrong I am doing here ? [System.Runtime.InteropServices.DllImport("User32.dll")] private static extern bool SetForegroundWindow(IntPtr handle); [System.Runtime.InteropServices.DllImport("User32.dll")] private static extern bool ShowWindow(IntPtr handle, int nCmdShow); [System.Runtime.InteropServices.DllImport("User32.dll")] private

EntityFramework : Invalid column name *_ID1

折月煮酒 提交于 2020-05-24 22:33:51
问题 I am trying to implement DbContext for couple of tables called ' Employee ' and ' Department ' Relationship between Employee and Department is many to one. i.e. department can have many employees. Below are the EntityFramework classes I designed ( CodeFirst approach ) [Table("Employee")] public class Employee { [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Column("Name")] public string Name { get; set; } [Column

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

∥☆過路亽.° 提交于 2020-05-15 03:35:31
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

ⅰ亾dé卋堺 提交于 2020-05-15 03:35:25
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

Executing powershell scripts in c#

吃可爱长大的小学妹 提交于 2020-05-15 02:08:27
问题 Below is the script I am using to try and execute my powershell script but whenever i run it i just get a blank command window. C# Code static void Main(string[] args) { string text = System.IO.File.ReadAllText(@"C:\Program Files (x86)\Backup Reporter\Required\edit_website.ps1"); using (PowerShell PowerShellInstance = PowerShell.Create()) { // use "AddScript" to add the contents of a script file to the end of the execution pipeline. // use "AddCommand" to add individual commands/cmdlets to