.net

Get Windows user name - different methods

In .NET there appears to several ways to get the current Windows user name. three of which are: string name = WindowsIdentity.GetCurrent().Name; or string name = Thread.CurrentPrincipal.Identity.Name; or string name = Environment.UserName; What's the difference, and why choose one method over the other? Are there any other ways?...

Having POCOs, Entities and ViewModels in a solution feels like overkill

The latest version of the Entity Framework got me in love, still at good as it is I don't like using entities objects as domain objects for all the obvious headaches, so what I'm doing is translating retrieved entity objects in my services and returning POCOs to whomever consumes the service. Thanks to automapper the translation from poc...

creating an Info-box like control in .NET 2

Hi, i want to create an info box in .net 2 (attached is an image with an example) I wanted to use a panel, but I cannot change the color of its border. is it possible to change this property? if so, how? Thanks, Shuky ...

Performance of C++ vs Virtual Machine languages in high frequency finance

I thought the C/C++ vs C#/Java performance question was well trodden, meaning that I'd read enough evidence to suggest that the VM languages are not necessarily any slower than the "close-to-silicon" languages. Mostly because the JIT compiler can do optimizations that the statically compiled languages cannot. However, I recently receive...

Generate strip/grid from photo in .NET

Is there any component available for generating image strips and grids from single photo? ...

OpenFileDialog Control - How Can I Grab the Selected Path and Show it in a Text Box?

Here is my snippet: private void btnBrowseCInv_Click(object sender, EventArgs e) { ofdBrowseVInv.Title = "Locate Customer Invoice File"; ofdBrowseVInv.Filter = "Portable Document Format (*.pdf)|*.pdf|All Files (*.*)|*.*"; ofdBrowseVInv.FileName = ""; ofdBrowseVInv.FilterIndex = 0; ofdBrowseVInv.InitialDirectory = ""; ofdBr...

How can I use dynamic LINQ in my asp.net project?

How can I use dynamic LINQ in Visual Studio 2008? I'm trying to use using System.linq.Dynamic but there is no intellisense. How can I use it? ...

How can I make a Visual Studio addon that posts my code to a website?

I'm trying to create an extension for Visual Studio that will post code from a given method and possibly the error message to my blog. I'm building a small wordpress blog for common mistakes I make so I can browser them later on possibly and help people out with the same issues. Is this possible in Visual Studio? ...

How can I download an XML file using C#?

Given this URL: http://www.dreamincode.net/forums/xml.php?showuser=1253 How can I download the resulting XML file and have it loaded to memory so I can grab information from it using Linq? Thanks for the help. ...

What is the best way to convert any currency into decimal in C#?

What is the best way to convert any currency into decimal in C#? public static decimal returnDecimalFromCurrency(string dataToCheck) { decimal varValue; if (!Decimal.TryParse(dataToCheck, NumberStyles.Number | NumberStyles.AllowCurrencySymbol, CultureInfo.CurrentCulture, out varValue)) { varValue = decimal.MinValue; } retu...

.NET Application Settings -> setting the null string

What should I type (in both cases) in my app.config's applicationSettings section so that, when I read Settings, I can get the following: Settings.Default.FooString == null Settings.Default.FooString == string.Empty ? I guess there is no way to achieve both situations, or am I missing something? Diffrerenciating whether string valu...

Getting wrong information when scraping XML with Linq.

Image I have this XML: <ipb> <profile> <id>335389</id> <name>stapia.gutierrez</name> <rating>0</rating> </profile> </ipb> I'm trying to get ID, Name and Rating. Any guidance? Here's what I have and what I receive: public User FindInformation() { string xml = new WebClient().DownloadString(String.For...

How do I read the fontName property of a IHTMLComputedStyle interface in C#?

Acoording to documentation, this property gives me a TCHAR, but when I see the source code, this is the declaration: [DispId(1011)] ushort fontName { get; } Anyway, I don't know how to neither get a TCHAR from a ushort or get a string from a TCHAR. Anyone? ...

[.NET] RDM Sockets

I've recently come across .NET's RDM Socket type (SocketType.Rdm) and its features sound very promising, sounding very much like a reliable connectionless protocol. However, I've found no examples of its usage, and little documentation on the protocol itself. First of all, how do I instantiate a socket of this type? Specifying SocketTyp...

Where do I catch this simple bug?

Here's the relevant code: Public class User.cs: public void FindByID(int id) { Parser parser = new Parser(id); ID = parser.FindID(); Name = parser.FindName(); Rating = parser.FindRating(); Photo = parser.FindPhoto(); Reputation = parser.FindReputation(); ...

Any reason I'd get a NullReference exception on Windows 7 only?

My C#, .NET 4, app runs fine on XP (media centre to be exact - don't ask). On Windows 7, it installs fine, but immediately borks. It complains about a NullReferenceException in the callback of a background worker. (I'd love to give you more information, but short of installing VS on the target machine, this is all I can get.) So, anyth...

How to force a number to be in a range in C#?

Hi, In C#, I often have to limit an integer value to a range of values. For example, if an application expects a percentage, an integer from a user input must not be less than zero or more than one hundred. Another example: if there are five web pages which are accessed through Request.Params["p"], I expect a value from 1 to 5, not 0 or...

How can I check if an XDocument has at least one child?

I'm trying to check if a user exists from an XML response. When a user doesn't exist the response is like this: <ipb></ipb> What would be the best way for me to (in code) verify that a user doesn't exist? I was thinking of checking if it didn't have any child elements but I'm somewhat confused. Thanks for the help! public v...

Image control URL setting

I have an image control .NET. <asp:Image ID="Image1" runat="server" /> How do I set the URL using code in C#, like { this.Image1. } ...

Page_Load(object sender, EventArgs e)---Why is "object" not capitalised?

"object" here should refer to the "Object" class. As with all class identifiers in the .NET framework, it is supposed to be capitalised although not case sensitive. But I realise in c# it is not capitalised by default. Why is that? Is it because C# is modelled after Java which had some sort of non capitalised object class? I can't rememb...