.net

Loading System.ServiceModel configuration section using ConfigurationManager

Using C# .NET 3.5 and WCF, I'm trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to). The obvious way is to use ConfigurationManager to load the configuration section and write out the data I need. var serviceModelSection = ConfigurationManager.GetSection("sys...

Is Visual C++ memory managed by the Dot Net framework

I have recently had an issue accessing MAPI through the dot net framework (explained in this artical) that in turn has generated memory access violation errors. To get around this I opted to use a third party component from code project with a visual C++ core however we still have the problems. I have never used visual C++ myself howe...

Interlocked.Exchange, but not for booleans?

Is there an equivalent for Interlocked.Exchange for boolean? i.e., an atomic exchange of values that returns the previous value and doesn't require locks? ...

How to copy a file in C#

I want to copy a file from A to B in C#. How do I do that? ...

C# for Java Developer

I'm looking for freely available resources that will help me pick up C# language and some of the basic API (like Collections). I already know Java fairly well, so looking for resources that assume background in Java. ...

What are the most important things to learn about .net as a Project Manager?

Thinking about getting into .net technology project management I've had plenty of experience with PHP projects: I'm aware of most of the existing frameworks and libraries, and I've written specs and case studies based on this knowledge. What should I know about .net? Which top resources would you recommend me to know so I can rapidly l...

Store data from a C# application

I've recently taken up learning some C# and wrote a Yahtzee clone. My next step (now that the game logic is in place and functioning correctly) is to integrate some method of keeping stats across all the games played. My question is this, how should I go about storing this information? My first thought would be to use a database and I...

Is there an easy way to create ordinals in C#?

Is there an easy way in C# to create Ordinals for a number? For example: 1 returns 1st 2 returns 2nd 3 returns 3rd ...etc Can this be done through String.Format() or are there any functions available to do this? ...

C# application detected as a virus

Regarding the same program as my question a few minutes ago... I added a setup project and built an MSI for the program (just to see if I could figure it out) and it works great except for one thing. When I tried to install it on my parent's laptop, their antivirus (the free Avast Home Edition) set off an alarm and accused my setup.exe ...

How does the ASP.NET "Yellow Screen of Death" display code?

I thought .Net code gets compiled into MSIL, so I always wondered how do Yellow Screens produce the faulty code. If it's executing the compiled code, how is the compiler able to produce code from the source files in the error message? Feel free to edit this question/title, I know it doesn't really make sense. ...

Best way to replace tokens in a large text template

I have a large text template which needs tokenized sections replaced by other text. The tokens look something like this: ##USERNAME##. My first instinct is just to use String.Replace(), but is there a better, more efficient way or is Replace() already optimized for this? ...

.NET: What are attributes?

What are they, what are they good for, and how to I create my own? ...

Memory leaks in .NET

What are all the possible ways in which we can get memory leaks in .NET? I know of two: Not properly un-registering Event Handlers/Delegates. Not disposing dynamic child controls in Windows Forms: Example: // Causes Leaks Label label = new Label(); this.Controls.Add(label); this.Controls.Remove(label); // Correct Code La...

Cleaning up RTF text

I'd like to take some RTF input and clean it to remove all RTF formatting except \ul \b \i to paste it into Word with minor format information. The command used to paste into Word will be something like: oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0) (with some RTF text already in the Clipboard) {\rtf1\ansi\deff0{\fonttb...

.NET - Excel ListObject autosizing on databind

I'm developing an Excel 2007 add-in using Visual Studio Tools for Office (2008). I have one sheet with several ListObjects on it, which are being bound to datatables on startup. When they are bound, they autosize correctly. The problem comes when they are re-bound. I have a custom button on the ribbon bar which goes back out to the d...

Path Display in Label

Are there any automatic methods for trimming a path string in .NET? For example: C:\Documents and Settings\nick\My Documents\Tests\demo data\demo data.emx becomes C:\Documents...\demo data.emx It would be particularly cool if this were built into the Label class, and I seem to recall it is--can't find it though! ...

Best Approach to Parse for SQL in PHP Files?

For my senior thesis, I developed a program that would automatically detect and suggest fixes to SQL injection vulnerabilities using prepared statements. Specifically the mysqli extension for PHP. My question for the SO community is this: What would your preferred approach be to detect the SQL in PHP source code? I used an enum contai...

WPF Image UriSource and Data Binding

I'm trying to bind a list of custom objects to a WPF Image like this: <Image> <Image.Source> <BitmapImage UriSource="{Binding Path=ImagePath}" /> </Image.Source> </Image> But it doesn't work. This is the error I'm getting: "Property 'UriSource' or property 'StreamSource' must be set." What am I missing? ...

Removing nodes from an XmlDocument

The following code should find the appropriate project tag and remove it from the XmlDocument, however when I test it, it says: The node to be removed is not a child of this node. Does anyone know the proper way to do this? public void DeleteProject (string projectName) { string ccConfigPath = ConfigurationManager.AppSettings["Con...

Testing .NET code in partial trust environments

I want to test the behavior of a certain piece of .NET code in partial trust environments. What's the fastest way to set this up? Feel free to assume that I (and other readers) are total CAS noobs. @Nick: Thanks for the reply. Alas, the tool in question is explicitly for unmanaged code. I didn't say "managed" in my question, and sho...