.net

How to handle NHibernate session lifetime using services?

In this question I asked about NHibernate session lifetime. I'm using a desktop application, but with client/server separation, so the conclusion is that I will use one session per server request, as the server side is where all the NHibernate magic happens. My problem now is how to handle it. I've had problems before with loading of r...

Is it possible to change a component name in a component designer in WinForms .Net

I've created a component whose name I'd like to be able to change while editing in the component tray. I've added a Designer action for a name property, but now I'm stuck. Looking at the property grid, I can see that the name property is parenthesised, indicating that it's not a regular property. Is this possible? ...

Why does WaitHandle implement IDisposable explicitly?

System.Threading.WaitHandle (and hence ManualResetEvent etc) implement IDisposable explicitly. This seems to discourage it's use (calling Close() achieves the same as casting to IDisposable and calling Dispose). I'm just wondering if there is a good reason for this? ...

Incorrect new Uri(base, relative) behaviour in .NET

When you create a new Uri like this: New Uri(New Uri("http://example.com/test.php"),"?x=y") it returns: http://example.com/?x=y It was supposed to return: http://example.com/test.php?x=y according to the every major browser out there (I'm not quite sure what RFC says though). Is this is a bug or is there any other function out ...

Split String Value C#

I have a string value which I need to get the middle bit out, e.g. "Cancel Payer" / "New Paperless". These are an example of the string format: "REF_SPHCPHJ0000057_Cancel Payer_20100105174151.pdf" "REF_SPHCPHJ0000056_New Paperless_20100105174151.pdf" ...

Replacement for ScriptManager when aiming for Ajax History functionality

When you are creating a Search for your Website, you Want the user experience to be as good as anytime and when you are browsing your gridview you want to be able to press the Back Button to go back to the previous viewed page. In asp.net with asp.net ajax it's possible when using the ScriptManager + Ajax Control Toolkit where there is ...

Entity Framework - When does it load referenced relationships automatically?

In what instances does Entity Framework automatically load child rows and other related rows as you use them? It seems like sometimes this is done automatically on property accessor, and sometimes you must do it explicitly. For example, if I have a table called Car, and a table called Wheel, and there are 4 wheels rows for each car row,...

.Net C# windows forms, listbox control question

I have a pretty simple form with a listbox, a text box, and two buttons. The list box items are populated from a sql database table. The user may chose to select one or multiple items from the listbox. The text box is used to write more details about the items in the listbox. One button can then be clicked to update another database t...

Lost title on tabs of tabcontrol

It looks like i've lost the title on the tabpage of my tabcontrol ? If I change the text in the properties I can see that the width of the tab has grown/is slimming But I see no text. And how to change the gray color on the edges of my tabcontrol ? ...

PrintingPermissionLevel, SafePrinting, and restrictions

There is a PrintingPermission attribute in the framework which takes a PrintingPermissionLevel enumeration with one of these values; NoPrinting: Prevents access to printers. NoPrinting is a subset of SafePrinting. SafePrinting: Provides printing only from a restricted dialog box. SafePrinting is a subset of DefaultPrinting. DefaultPrin...

.NET Garbage Collection - What does it affect?

We have a situation where we are considering forcing a garbage collection on a server that is very low on RAM (3.6/4GB used on average). No, it's not really an option to upgrade this server unfortunately. One of our service processes (written indirectly in C++ (don't ask...)) does work with the .NET components and then sleeps for 10 min...

Write data to specifc tag

Hello, Is it possible to write data to a specific RFID tag (to its user memory actually) by using Motorola's EMDK for .NET / the Symbol.rfid2.device dll ? Imagine you have 2 tags in front of you and you want to write data only to one of them. The WriteTag method doesn't seem to support this. Thanks. ...

Fetch controls in a tabcontrol

Howto reach the controls in a tabcontrol, I want to color all the textboxen into a color with a simple foreach method: foreach (Control c in this.Controls) { //btw I get the next error at this line: System.Windows.Forms.TabControl' is a 'type', which is not valid in the given context if (c == System...

write reports to word(both doc and rtf) and excel

I have no background in reporting tools. I'd like to generate some statistical tables and plots. Is VSTO(Visual Studio Tools for Office) good enough for this task? What's the main difference VSTO tool chains and other reporting tools, like crystal-reporting. ...

What is the correct way in C# to download a file from the Internet and write it on the fly?

Edit: This is done in the Compact Framework, I don't have access to WebClient therefore it has to be done with HttpWebRequests. I am creating a download manager application that will be able to have concurrent downloads (more than one download at once) and the ability to report the percentage completed and resume the downloads. This me...

How do I test my socket exception handling code?

I have the following code: try { mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, serverPort); mainSocket.Bind(ipEndPoint); mainSocket.Listen(MAX_CONNECTIONS); mainSocket.BeginAccept(new AsyncCallback(serverEndAccept), mainSocke...

format string- compile time checking

Is there any way to check the format string at compile time ? Example: Console.WriteLine("{0} is a really {1} site", "stackoverflow.com", "cool");//this will run //this will give an exception as only one argument is supplied Console.WriteLine("{0} is a really {1} site", "stackoverflow.com"); Exception:"Index (zero based) must b...

get length of data sent over network to TCPlistener/networkstream vb.net

It seems the most obvious thing, but I just can't work out how to get the length of bytes sent over a network using a TCPClient and TCPListener? This is my code so far: 'Must listen on correct port- must be same as port client wants to connect on. Const portNumber As Integer = 9999 Dim tcpListener As New TcpListener(IPAddress...

VS.NET: Project Refs vs. Assembly Refs

There's some debate here over which is better for referencing our common code base from other projects: by project or by assembly. I'm in favor of referencing the project, especially since we have automated unit tests that prove that the common code does what it needs to. The thought from the other camp is to lock down those projects...

wrapping MemoryStream in a using

I've been told that System.IO.MemoryStream need not be wrapped in a using block because there is no underlying resource, this kinda goes against what i've always been told about streams ("if in doubt, use a using"). Is this true? Why then does MSDN example use one (summarized below)? using(MemoryStream memStream = new MemoryStream(100...