.net

C#: How to communicate with SFTP server

Hi, I've written a service for our customer that automatically transmits files to given destinations using FTP. For historic reasons I'm using WinInet to perform the FTPing. All works well, but now the customer wants to add one destination that only accepts SFTP connections. I do not really like the idea of implementing this from scrat...

C# / .NET : Caching forms or speeding up form generation

I have a zoomable form-interface like MS Word. The form contains +70 controls (Richtextbox, checkbox, etc) that are positioned all over the form. The problem is that generating the form takes 2.5 seconds. Adding the 70 controls with panel.Controls.Add( ctrl) alone takes 1 second. (16 ms per call). Is there a way to cache the whole blan...

Unit testing Sql for logical reads

We have unit tests for our data access layer. This has helped to spot sql syntax errors. Now that we have these tests I would like to take it one step further. I would like to run the unit tests and find sql that has a high number of logical reads, Automatically.(to find sql in need of tuning) Adding "set statistics IO" to the sql is no...

If you aren't supposed to return collections to callers, how should you return a collection of data to a caller?

I am writing a method that's intended to return a dictionary filled with configuration keys and values. The method that's building up this dictionary is doing so dynamically, so I need to return this set of keys and values as a collection (probably IDictionary<string, string>). In my various readings (sources escape me at the moment), th...

Building a non sequential list of numbers (From a large range)

Hi All, I need to create a non sequential list of numbers that fit within a range. For instance i need to a generate a list of numbers from 1 to 1million and make sure that non of the numbers are in a sequential order, that they are completly shuffled. I guess my first question is, are there any good algorithms out there that could he...

python twisted equivalent in .Net

I am trying to write a socket server in .Net. I just read about twisted and found very interesting. Is there any equivalent library available for .Net ? ...

How to add keyboard shortcuts in ASP.NET for Focus / ButtonClicks

Hi there! How can I add some keyboard shortcuts (ctrl/alt/shift + something) to focus textboxes and/or perform button clicks? And, ss it possible to have a Keyboard shortcut to call some method in my .cs code-behind? Can anyone me tell me how? ...

How do I get schema information for a node in a XmlDocument?

Having a XmlDocument loaded with a XSD schema, how do I get the restrictions for a given node in the document? I would like to iterate through the document, and automatically correct errors where possible (eg: truncate strings that are too long, remove empty nodes that shouldn't be, etc.) I am doing this because xsd.exe does not take i...

Linkformat inside of Textmails

First off , my english is not very good so be nice :) My Problem : Via .NET Code i send mails to several receivers. These Mails contain a link that is decrypted like this : "http://www.abc.com/Defaul.aspx?id=o70pzUOz65E=" The Problem now is that, f.e. in Outlook the Link ends before the "=" and the "=" is simply written without b...

Recommended way to work with audio in .NET applications?

I'm trying to get started with a simple audio application under .NET 3.5 (preferably in VB.NET, but will happily use C#). What I'd like to do is: Continuously record audio from (the default) Windows audio input device in 8-bits-per-sample PCM format For every N bytes captured, do some analysis on the raw audio (some RMS and/or SPL calc...

String comparison equivalents

I believe these 2 lines are equivalent but after running into a strange issue I no longer believe this to be the case. String mimeType = context.Request.ContentType; (String.Compare("text/xml", mimeType, true) == 0)) is the same as : context.Request.ContentType.ToLower().Equals("text/xml") Are their implementations in the CLR any d...

Escape SQL Parameter

I need to work around an NHibernate bug I reported here. Essentially, NHibernate will generate multiple SQL parameters for the same HQL parameter, which results in problems for queries that use a parameter in a grouping construct. Until the bug is fixed, I figured I'd just concatenate the parameter into the HQL. Obviously this is suscep...

Is there a way to tell if the user would prefer metric or imperial without asking in C#?

Right now I'm doing: bool UseMetricByDefault() { return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalHours >= 0; } This works for distinguishing USA from Europe and Asia, but it ignores South America. Is there a better way? ...

Looking for an example of a custom SynchronizationContext

I need a custom SynchronizationContext that: Owns a single thread that runs "Posts" and "Sends" delegates Does the send in the order they are send in No other methods are needed I need this so I can unit test some threading code that will talk to WinForm in the real application. Before I write my own, I was hoping that someone coul...

How can I see the SQL generated by EF db.entityset?

I have something like this in a repository: var results = db.EventSet.Include("Events") .Include("TestResults") .Include("Events.Donors") .Include("Events.DonorPanels") .Include("Events.Locations") ...

DeleteTree fails on Hidden ReadOnly files

Hi, In my msbuild script I have to clean a directory, which has some hidden readonly subdirectories. I was using the DeleteTree task, but it fails on these. What is the best way to delete a directory recursively regardless of file attributes? ...

In C# .Net, how do I detect if a dialog showed up?

I'm working on an application which prints a report using the Microsoft XPS Document Writer driver. If the user attempts to overwrite a file which is open, the driver pops up an error dialog that the user doesn't have permission to save. However, on one QA's machine, the popup dialog never shows up. I want the application to popup its ow...

.Net WCF - Receiving & Sending XML

I'm new to WCF I have to create a WCF service that receives plain XML (not SOAP), does some processing then sends a reply message back in plain XML. I don't have a problem sending XML, I just need some tips on where to start. I'm familiar with creating web services in .Net with SOAP... with web services I would define the function to be...

Need help trying to figure out to grab a column of data

Hi I have something that looks like this H1 H2 CHK1 N1 D1 CHK2 N2 D2 CHK3 N3 D3 CHKN NN DN 1 2 3 4 5 6 7 8 9 10 11 // control positions if you had a counter counting with the foreach loop. So H1 & H2 are just some labels, Chk is checkboxes and N & D a...

Requested Execution Level for a dll

I've got a WinForms application that I am working on. There is one small piece of functionality that needs to be run as an administrator in Vista/Win7. I understand how I can set the requestedExecutionLevel for the application in the manifest. The trick is, I don't want to require the user to run the entire application as an administrato...