Click here to Skip to main content
15,881,882 members
Everything / Programming Languages / C#

C#

C#

Great Reads

by Wonde Tadesse
The other option will be to use Update Panel ASP.NET control as much as possible. It helps to retain the current position on the page whenever a postback happens to the page.
by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Dr. WPF
.NET 3.5 SP1 is here! It's time to break out your DirectX skills. This article provides the information necessary to get started using a new DirectX interop feature in WPF called D3DImage.
by John Atten
OWIN, Katana and Middleware Pipeline in ASP.NET

Latest Articles

by Zijian
Reusable codes for JWT security in business applications
by Mishael Ogo
A look at a simple SQL builder for Dapper
by honey the codewitch
Implementing a simple JSON parser with Visual FA
by Akram El Assas
Functional Programming in C# through Algebra, Numbers, Euclidean Plane and Fractals

All Articles

Sort by Updated

C# 

24 May 2019 by
These are valuable tips for every developer. Hope the OP will follow your suggestions in future. 5*
1 Mar 2011 by !Kerish11
Hi !I have a problem.I use the webbrowser class to login to a place.After I have logged into the site, I want to visit a link.The problem is when I have logged into the place, it won´t visit the link. If I show an messagebox after logged in and before I visit the link, it...
10 Feb 2015 by #1Gorilla
Hi! everyone. i am planning to make my own framework using ms enterprise libraries. (exactly i don't know whether it would be good to use ms enterprise libraries)but i have a trouble that i don't know where i should begin. should i design UML Classes first? or code anything ?if...
12 Apr 2015 by #1Gorilla
hi. i'm using staruml modeling tool. (but i'm novice to model in umlㅠㅠ)while i made a simple C# code and convert this code into uml, i am hit the roadblock. how should i express below codes in uml models. Code:public static IDataLayer GetInstance(){ DatabaseTypes dbType =...
7 Nov 2010 by #andy
Sample code to get you started
16 Jun 2015 by #dev_Preet
You can try this --> http://www.aspsnippets.com/Articles/Read-and-Import-Excel-Sheet-into-SQL-Server-Database-in-ASP.Net.aspx[^]http://csharp.net-informations.com/excel/csharp-read-excel.htm
17 Apr 2017 by #dev_Preet
i made an asp.net based web site using visual studio 2013 ,and want to run that web site in usb flash drive , is there any application which might help me regarding this problem? What I have tried: when i used tools which are developed for this job like cassini dev etc i got : Configuration...
21 Dec 2008 by #realJSOP
Parse a string with quoted elements, insert/add/delete elements, and is CLS compliant
4 Nov 2012 by #realJSOP
The classic word game using words and letter scores allowed in Scrabble
17 May 2008 by #realJSOP
One method for loading common and object-specific data from your app.config file.
28 Sep 2008 by #realJSOP
Put text on a bitmap, make your winform app go full-screen, and say hello to some simple LINQ code.
1 Oct 2008 by #realJSOP
Implement repetitive tasks at consistent intervals
2 Oct 2008 by #realJSOP
Discusses windows authentication and application-specific authentication for WinForm applications
11 Dec 2010 by #realJSOP
Scrape the My Articles page here on CodeProject to keep an eye on your articles.
12 Oct 2016 by #realJSOP
My views on how to be a proper programmer
24 Jun 2010 by #realJSOP
Create a dynamically resizable wizard form
17 Dec 2008 by #realJSOP
A not-so-dotNet way to allow multiple programs to share a single settings file
4 Jan 2009 by #realJSOP
A utility that you can use to "exercise" your inkjet printer without wasting a lot of ink or paper
20 Apr 2009 by #realJSOP
You should take "C#" out of your sig until you learn it.This has been asked/answered at least twice before. It's homework, isn't it? "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy...
5 Apr 2009 by #realJSOP
0) You're stupid.1) MSDN sucks, so that makes you stupid twice - first, because you're using MSDN, and second, because you don't understand what they've written (what little help they provide is written in clear English). "Why don't you tie a...
19 Mar 2010 by #realJSOP
Since this seems to be a particularly popular subject line, I thought I'd exploit it a little.To those of you required to come up with a project for school, do not ask what we think. Why? Because we'll tell you that you're not much of a programmer if you can't identify something like this on...
25 Aug 2008 by #realJSOP
Look at my reply to rotter512...Once you add the files as resources and compile the app, it's a piece of cake to extract them at runtime. "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your...
28 Oct 2008 by #realJSOP
The app.config is a damn handy thing, and unless you have some fairly bizarre requirements, you should make use of it. The only bad thing about the app.config is that assemblies (DLLs) cannot easily have their own app.config.User settings...
19 Mar 2010 by #realJSOP
This is not a question, but is too short to be an article. Learn from my mistake.Yesterday, I was testing a windows service I wrote using Visual Studio 2008 on a Windows 2000 machine. I had originally targeted .Net 3.5 when I created the project, and had to re-target the assemblies to 2.0...
15 Jan 2009 by #realJSOP
FXCop will trigger an "issue" if you do the 2nd thing, but FXCop is, after all, just a style guide and most of what it chokes/pukes on can safely be ignored. I tend to use method #2 in your examples. "Why don't you tie a kerosene-soaked rag...
2 Jan 2010 by #realJSOP
This is how I do it:public static System.Environment.SpecialFolder m_specialFolder = Environment.SpecialFolder.CommonApplicationData;
2 Jan 2010 by #realJSOP
Does aTags[0].InnerText do it?
6 Jan 2010 by #realJSOP
The biggest vulnerability is either the rookie programmer who is left to his own devices, or an experienced programmer that assumes too much.The language itself (and the .Net Framework in general) are NOT the problem with regards to security.
7 Jan 2010 by #realJSOP
I suggest you find another line of work. Maybe... running the machine that puts ridges on the sides of checkers.
8 Jan 2010 by #realJSOP
The first thing I would do is evaluate the string in the debugger BEFORE it's sent to your stored procedure. At that point, you can paste it into SQL Manager Express and try the query there to see WHERE your problem is.
9 Jan 2010 by #realJSOP
When I googled this (like you should have), I found this:In some situations a program may make the assumption that a variable always contains a positive value. If the variable has a signed integer type an overflow can cause its value to wrap and become negative, violating the assumption...
9 Jan 2010 by #realJSOP
You have to have Microsoft Expression to work on the project (or find the redistributables somewhere (probably the MSDN site).
9 Jan 2010 by #realJSOP
But why? Since the framework is already loaded, why not make use of the functionality instead of reinventing the wheel? This question makes no sense at all.
9 Jan 2010 by #realJSOP
You can pass just the date from a DateTime object - it's a property.DateTime dt = DateTime.Now;CallMySql(dt.Date);
9 Jan 2010 by #realJSOP
You could enumerate all child controls from the roignal form template and compare the list to all of the controls enumerated from the loaded form.Reflection is your friend.
9 Jan 2010 by #realJSOP
What d@nish said... (Content must be at least 30 characters? That makes it impossible to type "google" and be done with it.)
9 Jan 2010 by #realJSOP
My guess would be having more than one...
9 Jan 2010 by #realJSOP
We don't do people's homework for them.EDIT ================I strongly doubt the veracity of your claim that it's not homework. Since you're a programmer, and you know your requirements, why don't you at least TRY to do it yourself? Then, if/when you have problems, come back here and...
10 Jan 2010 by #realJSOP
Take a class, or read a lot of books.
11 Jan 2010 by #realJSOP
There is a collection in the ListBox object called SelectedItems, so try this:foreach (MyObject item in listBox.SelectedItems){ // do soemthing with the item}
11 Jan 2010 by #realJSOP
You could do a FileSystemWatcher that watches the newly created file to either look at it's size or wait for the file close event.
11 Jan 2010 by #realJSOP
Well, you can get a list of the current process' running threads, and then do something with the list:using System.Diagnostics;ProcessThreadCollection threadlist = theProcess.Threads;foreach(ProcessThread thread in threadlist){ // do something with the thread, thread.Id,...
11 Jan 2010 by #realJSOP
Use Spy++ to get a handle to the start button, and then post the appropriate system message using that hwnd.
11 Jan 2010 by #realJSOP
Instead of doing it that way, just create a thread pool and write a thread method that does the required processing, and queue up as many threads as your system can handle and let them all run simultaneously. The thread pool will automatically execute any thread that's queued up when there's...
11 Jan 2010 by #realJSOP
I wouldn't do it because it's a system DLL, and Vista/Weven don't like it when you mess with system DLLs.
12 Jan 2010 by #realJSOP
I believe your app didn't unload all the way the last time you ran it, and Windows thinks the file is still in use...
12 Jan 2010 by #realJSOP
I believe you have to set tabControl.SelectedIndex to the index of the tab you want to activate.
12 Jan 2010 by #realJSOP
BTW, it's much safer to use System.IO.Path.Combine when you're building a path like that.
13 Jan 2010 by #realJSOP
Put pointy brackets around it and parse it like XML with Linq-to-XML. Just treat everything like an Attribute.// our original stringstring text = "screen_fadetimeout=\"0\" font=\"Courier New\" fontsize=\"11\" linesize=\"4\" theme_color1=\"-1518056\" theme_color2=\"-9674238\"";// add our...
13 Jan 2010 by #realJSOP
I've used this online converter[^], but it's pretty bad at converting. Most of the other online ones are just as bad (as Christian has already noted.If you google "VB.Net to C# converter", you'll get quite a few hits on commercial products. Keep in mind that none of them will be able to do...
22 May 2010 by #realJSOP
Don't reinvent the wheel - use the one that's already on the cart.
15 Jan 2010 by #realJSOP
You can add a reference to the other project's assembly...
15 Jan 2010 by #realJSOP
You need to override one the event responsible for painting the toolstrip items. I don't know precisely which one, but it shouldn't be that hard for you to figure it out.
15 Jan 2010 by #realJSOP
You can't improve "average" developers via documents discussing proper object-oriented techniques. It's kind of like the old phrase, "You can lead a horse to water, but you can't make it drink."Second, if you can't describe ALL of the necessary OO terminologies in 30 pages, your article is...
13 Jan 2010 by #realJSOP
Try this instead:string pfile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "notes.txt");using (StreamReader sr = new StreamReader(pfile);
13 Jan 2010 by #realJSOP
Set the opacity property to 0.xx. Opacity of 0 is invisible, opacity of 1.0 is completely opaque (visible).
14 Jan 2010 by #realJSOP
Why won't this work?int divisor = 983;int dividend = 1;int scale = 2000;string padding = "";padding = string.Format("{0}{1}{2}", "{0:0.", padding.PadRight(scale, '0'), "}");string result = string.Format(padding, (double)dividend / (double)divisor);Of course,...
14 Jan 2010 by #realJSOP
I would have used a StringBuilder instead of a LinkedList, and decimal instead of int...decimal Rem = 10;decimal Number = 983;int MAXLEN = 2000;StringBuilder result = new StringBuilder("0.");for (int i = 0; i
14 Jan 2010 by #realJSOP
Here's a better answer:This is your version. It takes 2000 calculations and string moves, and generates incorrect results to boot:static string Method1(){ int iterations = 0; decimal Rem = 10; decimal Number = 983; int MAXLEN = 2000; StringBuilder result = new...
14 Jan 2010 by #realJSOP
Look at the text your tried to copy, and you'll see the appropriate characters.When you copy the code from the screen, it's substituting the escape codes for the characters.
14 Jan 2010 by #realJSOP
Run it through the debugger and find out.
17 Jan 2010 by #realJSOP
I used google, and what do you know? I found an article right here on CodeProject.Using Google is fun[^]
17 Jan 2010 by #realJSOP
Try this link:http://stackoverflow.com/questions/1593079/develop-an-application-similar-to-windows-explorer[^]And here's the pInvoke page about that method:http://www.pinvoke.net/default.aspx/Interfaces/IShellFolder.html[^]If you google the method name itself (like I did), you'll...
17 Jan 2010 by #realJSOP
Go here to learn how to use it correctly:http://www.pinvoke.net/default.aspx/shell32/SHGetFolderLocation.html[^]After that, use google to find examples of using it in C#. I'm sure that if you actually use the debugger provided in Visual Studio, you'll be able to find out what it's...
17 Jan 2010 by #realJSOP
Try adding this *AFTER* the StartInfo.FileName line:condor_status.StartInfo.WorkingDirectory = System.IO.Path.GetDirectory(condor_status.StartInfo.FileName);or set your own application's current directory to the same path as your CondorStatus app because it looks like it's writing a...
17 Jan 2010 by #realJSOP
It looks like you're leaving a message for someone specific, and probably in a forum for an article. Nobody has any idea what you're talking about.
20 Jan 2010 by #realJSOP
I found this using the magic answer tool we all know as google:"In control panel, select Administrative Tools > .NET Wizards. You can use the Trust Assembly wizard to change the permissions on all associated assemblies (including DLLs) with the project. You change it to "full trust" and...
17 Jan 2010 by #realJSOP
I found this on google:http://www.c-sharpcorner.com/UploadFile/perrylee/ScreenCapture11142005234547PM/ScreenCapture.aspx[^]Before using that example, I would check pInvoke for the correct signatures of the interop calls because I'm almost positive that what you see at the link provided...
17 Jan 2010 by #realJSOP
Why are you comparing label values? That's really bad form. The code you posted doesn't make any sense at all.
17 Jan 2010 by #realJSOP
I ended up just putting label controls where I wanted text. I don't think you can label the tick marks in the control itself without overriding it with your own control.Beyond that, the labels you want don't mean the same thing. The tick marks on a track bar control are evenly spaced and...
17 Jan 2010 by #realJSOP
Catch the event that displays the form when you're restoring it from the systray, and add this line to the event handler.this.WindowState = FormWindowState.Normal;
17 Jan 2010 by #realJSOP
Use Split('/') to get the separate lines, and then for each line, use Split(' ') to break the line up into words.At that point, you can use the TryParse() method for the desired type to retrieve data. You'll have to do additional coding to determine exactly what data you're getting (to see...
17 Jan 2010 by #realJSOP
You could use Linq-to-XML to parse the a tag and retrieve the href attribute. That will give you the link itself.
17 Jan 2010 by #realJSOP
Or, you can do this:string myString = string.Format("{0:00}", number);
18 Jan 2010 by #realJSOP
If you are dividing int values, you must cast them to doubles if the receiving variable is a double.For example, this will result in "0":int x = 1;int y = 2;double z = x / y;Where this will result in the expected 0.5:int x = 1;int y = 2;double z = (double)x / (double)y;
18 Jan 2010 by #realJSOP
Try this:this.Bounds = Screen.PrimaryScreen.Bounds;this.TopMost = true;
19 Jan 2010 by #realJSOP
Google is your friend. No - really - it is.
19 Jan 2010 by #realJSOP
Philosophical opinions aside, there are no advantages to a given programming language. Each one is useful and can be "the best choice" for a given task. Only the programmer can determine a given language's fitness for a particular task, and even that decision is based on his own level of...
19 Jan 2010 by #realJSOP
I'm positive that you don't have the skills required to do this.
20 Jan 2010 by #realJSOP
Beyond what others have said, you really shouldn't throw a message box at the user when they type an invalid character. Just beep the speaker, and be done with it.
20 Jan 2010 by #realJSOP
I wouldn't visit a site that I knew could scrape files off a client machine. In fact, I'm pretty sure that unless you convince the user to install an ActiveXcrement module, this is pretty much impossible to do.
20 Jan 2010 by #realJSOP
Try it this way in your form class:private bool initialized = false;public MyForm(){ InitializeComponents(); this.initialized = true;}void checkbox_clickevent(object sender, EventArgs e){ // initialized prevents the message box from being displayed in the ...
20 Jan 2010 by #realJSOP
Take a programming class (actually, you should take a BUNCH of programming classes). Remember, google is your friend.
20 Jan 2010 by #realJSOP
This question cannot possibly elicit a "quick answer". Try posting in the appropriate forum instead.
21 Jan 2010 by #realJSOP
Look into using a BackgroundWorker object. I would give you specific code, but there are plenty of examples on the internet. Just use google to find them.
21 Jan 2010 by #realJSOP
You could try something like this before doing anything with the data:string myString = "a b c";do{ myString = myString.Replace(" ", " ");}while (myString.IndexOf(" " >= 0);myString = myString.Trim();
21 Jan 2010 by #realJSOP
USE THE DEBUGGER.It would have allowed you to discover that there is only one item in the rdr object. Using a value greater than 0 will almost always result in an exception.
21 Jan 2010 by #realJSOP
Why use math when you can do it with the framework?int value = 12345;string text = string.Format("{0:0 0 0 0 0}", value);
21 Jan 2010 by #realJSOP
Handle the TextChanged event for the textbox, and eliminate anything in the TextBox.Text property that's not a numeric digit.
22 Nov 2011 by #realJSOP
A useful technique that could be used for winform apps which require a login dialog
22 Jan 2010 by #realJSOP
Use a Guid - guaranteed to be unique every time.EDIT ==========Ooops - someone already suggested it...
22 Jan 2010 by #realJSOP
Yes. You have to write an unmanaged DLL, and then use InteropServices in your managed assembly to get to the DLLs functionality.
22 May 2010 by #realJSOP
No change is too small for a complete regression test.