Click here to Skip to main content
15,891,033 members
Everything / Programming Languages / C# 4.0

C# 4.0

C#4.0

Great Reads

by Igor Ladnik
Wrapper to facilitate usage of TCP sockets
by Sacha Barber
It would probably be like Cinch, an MVVM framework for WPF.
by Roman Kiss
This article describes a design, implementation and usage of the Custom Routing Manager for managing messages via Routing Service built-in .Net 4 Technology.
by Adam David Hill
All the juicy tricks and scandalous shortcuts which helped us ship our competition game on time

Latest Articles

by Elmue
An easy to use 3D control which can be integrated into an application in a few minutes
by NikStar
Using OutgoingMessageProperties and OperationContextScope to implement authorization by http header for WCF client that communicates with non WCF-based web services.
by Siddhartha S.
WPF smart client demo of nitty gritty of MVVM for a real life LOB application
by Shivprasad koirala
Understanding two terminologies - reflection and dynamic keyword

All Articles

Sort by Updated

C# 4.0 

N 30 Apr 2024 by Richard Deeming
As Dave said, it's not as simple as changing the target framework and adding the UseWpf item; the project format has changed quite significantly. Undo your changes, and use the CsprojToVs2017[^] command-line tool to update your project file to...
N 23 Apr 2024 by Dave Kreskowiak
You most likely don't have a reference to PresentationFramework.dll set in your project.
N 23 Apr 2024 by s yu
I am revising a .Net FW4 project in order to add some WPF components (in net 6). In the revised .csproj,I added the 2 lines in the
17 Apr 2024 by Richard Deeming
If I've understood your question correctly, you're hosting your application files on a shared folder on your server, and want to see who has the file open on a different computer. Doing this manually would involve opening the "shared folders"...
17 Apr 2024 by OriginalGriff
Unless you have admin permissions on that machine, you aren't going to be able to kill the process from the server - you don't own it, the user who started it does - where the EXE file was located is irrelevant once the process it started. What...
16 Apr 2024 by Graeme_Grant
If I am understanding you correctly, you want to find one app from another and close it. I have written an article called Silent ClickOnce Installer for Winform & WPF in C# & VB[^]. There is a class named AppProcessHelper that can identify if...
16 Apr 2024 by Meena_16237389
I want to find process(my application which is .exe file hosted on server) running on other user's machine and kill that process. using C# code. What I have tried: Below code can find only one user and the process running on that one user's...
10 Apr 2024 by Graeme_Grant
This part of the error message is explicit: ...System.Windows.Forms.Calendar.dll' doesn't contain any UserControl types It sound like you are either missing another DLL or you are trying to use something that is not in that DLL.
10 Apr 2024 by Maciej Los
In the System.Windows.Forms namespace there is only a MonthCalendar. See: MonthCalendar Class (System.Windows.Forms) | Microsoft Learn[^]
10 Apr 2024 by Dave Kreskowiak
The only person who can tell you that is the person who wrote the control. If you're talking about something you found in an article here on CP, there is a forum at the bottom of the article where you can ask your question. If it's something...
10 Apr 2024 by Member 16163852
I get the following exception and i don't know how to solve it. It looks like a terrific control and i'd like to use it! What I have tried: replace the System.Windows.Forms.Calendar.dll for the one in the demo, wich did work, but still no...
22 Feb 2024 by Maciej Los
Quote: as seen above last 2 row in datable is not in valid "dd-mm-yyyy" format Really? Take a look at below example: List lstOfDates = new List() { "22-07-2024", "23-09-2024", "2024-09-23", "1234-09-23" }; ...
20 Feb 2024 by Member 16206966
The desired RowDetailsTemplate content is available just then the row is expanded. Till this event (see LoadingRowDetails) the content is null and Try to find it with DataGridDetailsPresenter.ContentTemplate leads to an exception:...
20 Feb 2024 by Richard MacCutchan
How can you be sure there are 10 items in the combo? You should use the Count property of the Items collection. That way you can have any number of entries, and can always guarantee to find the last one. As to colouring the last one, take a look...
20 Feb 2024 by Pete O'Hanlon
It depends what you mean by coloured as to how you would solve this (and I'm assuming you're using Windows Forms here). If you wanted to change the foreground colour, you could use something like thisprivate void comboBox1_DrawItem(object sender,...
19 Feb 2024 by glennPattonWork3
Hi All, Can the last item in a Combo Drop down be colored Highlighted? The need is to highlight the last item in a combo box (or list box if thats easier...) What I have tried: To fill the box: for (int i = 0; i
15 Feb 2024 by Richard Deeming
The error message is slightly confusing, but once you see it, the problem is obvious: Quote: Please specify one of either an InputStream or a FilePath to be PUT as an S3 object. The error is telling you that you have specified both an...
15 Feb 2024 by itsathere
File.WriteAllBytes("D:/" + model.FileBase.FileName, model.FileBase.Data); byte[] bytes = Convert.FromBase64String(model.file); using (var inputStream = new MemoryStream(model.FileBase.Data)) { ...
14 Feb 2024 by Hailu Worku Obsse
To show and hide a window in a Windows Forms application using a shortcut key, you can handle the KeyDown event to detect when the shortcut key is pressed. Then, you can toggle the visibility of the form accordingly. Here's a basic example of how...
14 Feb 2024 by jb.pearson2
You need to get a hook into the win32 api. As soon as you hide your .net form, the events and event subscribers stop working because they only exist in the container of the form. You need something like this. using System; using...
12 Feb 2024 by Elmue
An easy to use 3D control which can be integrated into an application in a few minutes
3 Feb 2024 by M Imran Ansari
For bulk emails, you must also take care of certain restrictions on receiving and sending have been imposed to counteract spam, mass-mailing worms, or viruses. These limits play a crucial role in safeguarding system and ensuring the safety of the...
3 Feb 2024 by Noman Suleman
I'm currently engaged in creating a marketing email, intending to send personalized bulk emails to individual customers. However, if some of the email addresses happen to be nonexistent, there's a risk of my MS Office 365 account getting blocked...
3 Feb 2024 by OriginalGriff
We can't do anything about that: if you send a lot of material that MS considers spam (such as but probably not limited to a lot of bounce backs) then they will block your account. It's not a matter of changing your software to avoid it, it's a...
25 Jan 2024 by M Imran Ansari
You can use the ClientIDMode="Static" attribute on the control (DropDownList), which ensures that the client ID remains the same as the server ID.
25 Jan 2024 by Member 7513082
I am having issue while passing the client id value of asp.net control getting changed in JavaScript. I am getting exception while passing the value of a dropdown (ctl00_cphDDS_drdInstructionCode) as updated below. In one server it is rendering...
23 Jan 2024 by Zain Khan 2024
It looks like you want to validate data in an Excel file and add an error message to a new "Error" column for rows that contain invalid data. Additionally, you want to download the Excel file with the added error information. Here's a suggested...
22 Jan 2024 by OriginalGriff
Quite probably, you can't. Start by checking the excel source: unless the date is in a column that Excel recognises as a date (i.e. is formattable in Excel) then it's a string and can contain anything including valid dates, invalid dates, wrong...
22 Jan 2024 by Akshay malvankar
Hi convert data from excel to datatable now i want to validate the date format from datable using LINQ on datatable, My datatable Row id date 1 22-07-2024 2 23-09-2024 3 2024-09-23 4 12334-09-23 as seen above...
22 Jan 2024 by Member 10215662
Hi :) Not my code, just adapted for x64 versions (maybe helps someone so many years later). Is just for getting current RDP (Remote Desktop) client hostname. Private Declare PtrSafe Sub WTSFreeMemory Lib "wtsapi32.dll" (ByVal pMemory As Any)...
19 Jan 2024 by Akshay malvankar
Hi I want to validate datable and if there is an any error in row of data table then i want add Error Msg in Error Column "Excel D: column contain Invalid data". in that row which consist error in row. and if any error occured i want to download...
27 Dec 2023 by codiagirl
I have a child view name UploadImage and parent view name CROCOnfig, when I access child view by using button in parent view,it works fine, but when I try to render child view in parent view,it throws error that model is null. I have placed child...
24 Dec 2023 by NikStar
Using OutgoingMessageProperties and OperationContextScope to implement authorization by http header for WCF client that communicates with non WCF-based web services.
29 Nov 2023 by Dave Kreskowiak
Assuming Windows Forms: The .Focus() method does not work in the Form_Load handler because, well, there's no control yet as far as the UI is concerned. In the Form_Load handler, the form is LOADED, NOT SHOWN YET. If you're going to set the...
29 Nov 2023 by Choroid
I am still trying to lean C# and I am playing with Global Variables or should I say static variables. I went to this link to learn how to set Focus on a textbox it kind of works. How to: Set Focus in a TextBox Control - WPF .NET Framework |...
8 Nov 2023 by CHill60
That is not a program it is a Class. Assuming you are just trying to create a Console program it could be as simple as using System; public class Program { public static void Main() { // put some code here } } Again, assuming you...
8 Nov 2023 by CHill60
Quote: That's exactly what i was waiting for . A nonsense comment. thanks Not really nonsense though is it? As Maciej says in his comment, it's "unfriendly to the UI" and Gerry says "without smashing the keyboard". At the very least it's...
7 Nov 2023 by Lyrica Sugiyama
using System; namespace BankAccountManagemnetSystem { public class BankAccount { private decimal balance; private int amount; public BankAccount(decimal initialBalance) { balance =...
6 Nov 2023 by Ankit Goel
I have a textbox and a datagridview with some results. I am looking for a way in which if the user is typing something in the textbox and in between, he uses his mouse and clicks on the datagridview, the focus should not leave the textbox means...
6 Nov 2023 by Akshay malvankar
I am using iText and want to fetch the pdf version of my pdf. I am using the following code: using (PdfReader reader = new PdfReader(filePath)) { // Check the PDF version against the specified standard ...
27 Oct 2023 by Akshay malvankar
I have one API which gives different responses in reply: For example: API gives response: { "status_id": 200, "status_msg": "Successful", "unique_trans_id": "CLIENTAPI202305260134469", "info": { "case_id": "MG.0523.30" ...
27 Oct 2023 by Richard Deeming
This sort of API response is a nightmare to work with, but seems to be quite popular amongst the loosely-typed language crowd. To read it in C#, you will need a custom JSON converter. For example: public class OutputInfo { public string...
25 Oct 2023 by Dave Kreskowiak
Looking at the source code for iTextSharp, it's not GetPdfVersion you should be calling, but just PdfVersion, which is a property of the PdfReader object, not a method. using (PdfReader reader = new PdfReader(filePath)) { // Check the PDF...
25 Oct 2023 by Richard Deeming
The GetPdfVersion method is defined on the PdfDocument class, NOT the PdfReader class. iText 7 7.1.8 API: iText.Kernel.Pdf.PdfDocument Class Reference[^] You can't just call a method from one class on a completely different class which doesn't...
3 Oct 2023 by ahmed_sa
I work on Blazor application server side. I design web API to interact with razor pages. My issue is which is suitable for my scenario? Using ADO.NET or Entity Framework Core? What I try is as below: So is using data reader ADO.NET better or...
2 Oct 2023 by Graeme_Grant
I would compare EF Core with Dapper, not Ado.Net. Here are a couple of videos that go into detail... * Entity Framework Core vs Dapper Performance in 2023 - YouTube[^] * Making Entity Framework Core As Fast As Dapper - YouTube[^]
12 Sep 2023 by Southmountain
I have an old project demo to play around with. Now I have a question on how to use this dataset. It looks like this dataset is added by inserting a new item menu and selecting dataset class. This dataset has one datatable defined in it. Here...
10 Sep 2023 by Richard Deeming
That's a "typed DataSet": Typed DataSets - ADO.NET | Microsoft Learn[^] Typed vs. untyped datasets - Visual Studio (Windows) | Microsoft Learn[^] As far as I can see, they should work fine in .NET Framework projects, but I don't think they've...
10 Sep 2023 by Dave Kreskowiak
That's a really old project. You're not going to find anything on it because that's the really old designer generated code used by old versions of Visual Studio, like 2010 and older, I think.
19 Aug 2023 by Rajesh Kumar 2013
How can I use Intersect to compare list? Here, I am getting exception: Newtonsoft.Json.JsonReaderException: 'After parsing a value an unexpected character was encountered: ". Path 'functionalities', line 1, position 278.' What I have tried: ...
18 Aug 2023 by PIEBALDconsult
Dig this: System.Collections.Generic.HashSet keyword = new System.Collections.Generic.HashSet ( System.StringComparer.InvariantCultureIgnoreCase ) { "SELECT" , ...
16 Aug 2023 by Graeme_Grant
Based on our discussion in the first solution, I have posted this as a separate solution as it is a very different approach and more involved then the first solution. Okay, So you want to convert all JSON Properties & values to a...
16 Aug 2023 by Graeme_Grant
First thing, your JSON data is invalid. Here is the corrected data: { "Id":null, "FName":"create", "LName":"Denny", "DateofJoining":null, "Date":"2023 - 08 - 01T00: 00:00", "CreatedBy":"ICC0000389", "levels":{ ...
16 Aug 2023 by snorkie
Your JSON is invalid. When you update the JSON to a valid string, the program works. Run it through a validator and you'll see that there is an extra quote at the end of the functionalities array and again at the end of the functionalityList...
13 Aug 2023 by OriginalGriff
We can't directly help - we have no way to examine your system(s) and work out what might be causing the problem. But ... you mention of a "large pdf" implies that the document generation is taking too much time and if you are doing that in a...
13 Aug 2023 by Member 15709759
I am generating large report using ironpdf. The issue is that my web page is going to idle after loading around 3 to 5 minutes. In local it is working fine and it may take to 3 to 5 minutes to generate report and save as pdf, but in live...
10 Aug 2023 by PIEBALDconsult
I got a bad feeling about this... Here's how to do it using HashSets directly rather than mucking about with Linq, but it's not a very good technique: System.Collections.Generic.Dictionary dictionary1 = new...
10 Aug 2023 by PIEBALDconsult
A problem with this solution and what you have asked for is that the JSON file you are reading may contain millions of objects and this technique has certain inefficiencies which will not scale well. You should not keep building a HashSet from...
10 Aug 2023 by Rajesh Kumar 2013
Hi, Using LINQ, how can I compare two Dictionary for search same text contain in value, not consider key? What I have tried: Dictionary dictionary1 = new Dictionary(); ...
10 Aug 2023 by Graeme_Grant
You need to fix your key issue in the second Dictionary. You have defined it as: Dictionary If you want to mix int and string, then change to: Dictionary Now, you're looking for the intersection of the 2...
9 Aug 2023 by Rajesh Kumar 2013
Hi, How to find if "join" text contains only inside Value, not consider Key? What I have tried: public bool IsValid() { string val = "join"; bool isNotValid = false; string jsondata =...
9 Aug 2023 by PIEBALDconsult
Your question is a bit vague and should be improved. Here's another RegEx-based technique, but I don't recommend it as a general solution. string sought = "join"; string jsondata =...
9 Aug 2023 by OriginalGriff
The best way is to use something like Newtonsoft Json.NET[^] to read the whole Json into "sensible" classes and process those, but it could be done with a Regex:(?".*?":)(("(?.*?)")|(null)) Will extract all the Key/ value pairs. To...
8 Aug 2023 by Member 10371658
I did the HttpWebRequest and got the following HttpWebResponse: response=1&responsetext=SUCCESS&authcode=123456&transactionid=8607693510&avsresponse=N&cvvresponse=N&orderid=&type=sale&response_code=100 i want to convert this response into...
8 Aug 2023 by OriginalGriff
JSON data looks like this: {"name":"John", "age":30, "car":null} Your data is an HTML Query string, where each term is separated by ampersands, each of which contains key and value parts seperated by equal signs. To process this, use...
5 Aug 2023 by Rajesh Kumar 2013
Hi, I have a razor page called ForgetPasswordOtp.razor page with directive @page "/ForgetPasswordOtp/{UserName}" . How can I prevent the same page access from another browser tap. It is causing a problem like everyone can access the page...
5 Aug 2023 by Graeme_Grant
You would need to throttle the requests on the server side using a timed cache of the username as it is the only data being passed. Then when the server receives the request, check the cache and either allow the process to continue or return a...
4 Aug 2023 by Vid S 2023
Hi, I'm trying to create a .net c# winforms application , to interact with a master device over serial port. The application should simulate 3 slaves, by responding to the master device requests. I'm trying to use NModbus, but i'm lost on how to...
31 Jul 2023 by Engineer khalid
hello i want to change System date using Registry What I have tried: using Microsoft.Win32; private void button3_Click(object sender, EventArgs e) { RegistryKey regkey = ...
31 Jul 2023 by Andre Oosthuizen
To know what date format a user's machine is set to, you can use the 'CultureInfo' class and the 'DateTimeFormat' properties. You CAN NOT change a user's machine date time formats, you will not have many users left within the first day of your...
30 Jul 2023 by OriginalGriff
To add to what Dave has said, not only do you need Admin rights to change them but even if you could change the system date and / or time, or the system date format via the registry, it would be a very bad idea as it would affect the whole...
30 Jul 2023 by Dave Kreskowiak
Kind of odd because you cannot change the system date in the registry. It looks like you're trying to change the format of the date presented to whatever date you want and that's not going to work. But, I see one glaring problem right off the...
28 Jul 2023 by Member 14475436
What is the difference between AmbientValueAttribute and DefaultValueAttribute in c# winform? I find that they are used to set default values, and feel that the presence of AmbientValueAttribute is superfluous. What I have tried: I've seen the...
27 Jul 2023 by Richard MacCutchan
See AmbientValueAttribute Class (System.ComponentModel) | Microsoft Learn[^].
25 Jul 2023 by programing pro
It is a control that is used to create a hyperlink. It responds to a click event. We can use it to refer any web page on the server. To create HyperLink either we can write code or use the drag and drop facility of visual studio IDE. This...
24 Jul 2023 by Rajesh Kumar 2013
Hi, I have a RadzenDropDown component and it's bind-Value should be set 'Zero' on page load.
23 Jul 2023 by OriginalGriff
FIrstly, this line is a bit ... overcomplicated:varname = ("0").Split(new string[] { "," }, StringSplitOptions.None); You can get the same result with varname = "0".Split(",", StringSplitOptions.None); orvarname = "0".Split(',',...
21 Jul 2023 by Graeme_Grant
It depends on how it will be used. If you want to be non-culture-specific, then check out this article on CP: Culture Specific Number Formatting in ASP.NET[^]. The code is a console app. If you are doing it for yourself, or the app is ignorant...
21 Jul 2023 by Boopalslm
I am using c# windows application 2010, I have a total amount of 150000, and the result comes now I want 1,50,000.00. what to do any one give me suggestions. What I have tried: I am using c# windows application 2010, I have a total amount of...
21 Jul 2023 by Richard MacCutchan
Use the appropriate currency formatter, as described in the documentation: Standard numeric format strings | Microsoft Learn[^].
16 Jul 2023 by Graeme_Grant
I decided to do some benchmarking after Andre's post. The results were very interesting. As mentioned in my comment to Andre, I thought that Span would be faster than Richards's solution. After seeing the results I wanted to find a faster...
16 Jul 2023 by MS2023
I want to result like below : List a1=new List(){"a","b","c","d"}; List a2=new List(){"1","2","3"}; Output : a1b2c3d Please help how to achieve without using inbuilt function. What I have tried: I am new to...
16 Jul 2023 by Richard MacCutchan
Something like: StringBuilder output = new StrinBuilder(); for (int i = 0; i
16 Jul 2023 by Joshi, Rushikesh
Hi All,I am a .Net expert and don't know much details about Python (Used python.Net long back).I came across below script from http://www.kunaldua.com/blog/2009/12/reliance-wireless-broadband-auto-login-script/[^] site.I would like to convert below code to C#, so I can create a small...
16 Jul 2023 by khalidezzat
use www.codeconvert.ai/app[^] using System; using System.Net; using System.Collections.Generic; class Program { static void Main(string[] args) { string username = "1111111111111111"; string password = "password"; ...
15 Jul 2023 by Graeme_Grant
Just for fun, I asked ChatGpt the following: merge lists to create combined values in a new list using c#: List a1=new List(){"a","b","c","d"}; List a2=new List(){"1","2","3"}; Output should be: a1b2c3d The...
14 Jul 2023 by Engineer khalid
Hello Help me to find the proper language to write a program for a shop assume I have a buityshop. the customer enters the program and select the type of work they need and pay the price through visa or other. They will receive the conformation....
14 Jul 2023 by OriginalGriff
The language to use is almost always the one you know best, unless there are hardware reasons why that language cannot be used (like you want to code for an iPhone for example - there you are pretty much Objective-C only). So ... open VS, and...
13 Jul 2023 by pandian78
To set this permission, right click on the Excelsheet folder (or whichever other folder you have put the file in) and select Properties. Look for the Sharing tab. Click share button and give read and write permission to every one name then click...
13 Jul 2023 by Member 12702056
What is the difference between char zero and normal zero in c++? especially i mean in c++for example,char x=0;int x=0;and char x='0'or just like '0'what is the difference between all of them?what is the exact meaning of them?Please,help me :)What I have tried:I know that...
12 Jul 2023 by Member 9929607
I have c# desktop application with MS-Sql server as back end. This desktop application will be running in two different systems (database will also be in local system), I want the data to be synced between these two systems bidirectionally. For...
12 Jul 2023 by Graeme_Grant
Expanding on @OriginalGriff, you could use SignalR (Microsoft Learn)[^] for realtime updates. This would remove the need to be on the same local network and is a managed with typed support.
12 Jul 2023 by OriginalGriff
If the systems are both on the same LAN or WiFi network, then Sockets in .NET - .NET | Microsoft Learn[^] is probably a good place to start.
10 Jul 2023 by Rajesh Kumar 2013
Hi, I am getting error while converting List to IList. How can I solve this? What I have tried: private IList _orgLevel3; List orgLevel3 = await OrganisationService.GetListOfOrgDetails(3); ...
10 Jul 2023 by OriginalGriff
The problem isn't the List / IList implicit cast, that works as you would expect: List myList = new List(); IList myIlist = myList; The problem is that your IList type doesn't match the List type...
6 Jul 2023 by Rajesh Kumar 2013
Hi I am trying to get value "1790,1234,345,67" to the variable getProductValue . But it is not getting from my dictionary object. What I have tried: Dictionary dictionary = new Dictionary(); IEnumerable...
6 Jul 2023 by Richard Deeming
That's a really terrible way to get the value associated with the specified key! Instead, use the TryGetValue method[^]: Dictionary dictionary = new Dictionary { [1] = "0,1,2", [3] = "1790,1234,345,67" }; ...
6 Jul 2023 by Graeme_Grant
Google search is powerful for looking up this type of question. I put it into google search for you: How do I get dictionary value by using linq where and select C#? - Google Search[^] The first search result was: Linq Query Dictionary where...
1 Jul 2023 by Ankit Goel
Hi , i have created a custom datagridview and trying to move my cell to the right when i presses enter key (instead of going to down on pressing enter key ) but i found that i have to press enter twice to move rightwards . when i presses enter...
1 Jul 2023 by Graeme_Grant
Microsoft Excel moves the cursor down a row if the enter key is used. I would recommend using this as it is familiar. However, to move the cursor right, not down, on using the Enter key, it is possible. The following code will wrap the cursor...