.net

How to play a sound in WPF

Hi, I'm a novice C# programmer and am having trouble getting music to play in my WPF (Windows) application using VS 2008. This is a web app. What I think is happening is myMediaElementExample variable is empty at the time it is used to execute the "Play" method in the ExpenseReportPage.xaml.cs file. Right now this program builds, bu...

Can the performance timer "% Time in GC" be wrong?

We found that, since today, the "% Time in GC" (percent time in Garbage Collector) performance timer, steadily stood on 100% with only occasionally a bit lower. Even when at night no visitors were online. Then I placed App_Offline.htm in the root. Usually this brings down all ASP.NET activity. But for some odd reason, the "% Time in GC"...

How do I merge multiple .net assemblies into a single assembly?

I have a .net application with about 10 assemblies. It would be nice to have them all together as a single assembly. Is this possible? How do I do it? I guess something like a jar file for java applications. Thanks ...

How to cast an object programmatically at runtime?

Suppose I have a custom control like: MyControl : Control if I have code like this: List<Control> list = new ... list.Add (myControl); RolloutAnimation anim = list[0]; I know I can do it at compile time but I wanna do it at runtime and access MyControl specific functionality. ...

why is use of "new NetworkCredential(username, password)" not working for Basic Authentication to my website (from a WinForms C# app)???

Hi, I have a website that uses Basic Authentication (username/password). Why is the following code not working? When I run it the web application takes me to the login controller, whereas I'm expecting that it should already be authenticated given I'm populating the credentials. In other words I'm trying to confirm how, in .NET, I...

creating a custom attribute to control rounding behavior

I have a class with a lot of Decimal properties that are used for financial calculations. There are rules that specify how many decimal places to use when rounding each number. There is no global rule - some are two decimal places, some 0, some 8, etc. I'm trying to figure out the easiest way to approach this. I want to avoid having ...

Casting a list of objects to their interface type in C#

I know I can cast an object from its own type to its interface type like so: IMyInterface myValue = (IMyInterface)MyObjectThatImplementsMyInterface; How can I cast IList<MyClassThatImplementMyInterface> to IList<IMyInterface>? ...

pdf resize in browser before opening

Response.ContentType = "Application/pdf"; string FilePath = Server.MapPath("reliance.pdf"); Response.WriteFile(FilePath); Response.End(); How can we resize the pdf file before it gets open in browser....can you tell me? thanks ...

Why isn't this If Statement executing?

Background I have a Windows Form with the following items ComboBox TextBox Two Buttons: Forward and Back A class - Items which holds a string int and double members if (ComboBox1.SelectedIndex == 2 && Items[index].Price > 50.00 ) { txtManu.Text = Items[index].Manu; txtPrice.Text = Convert.ToString(Items[index].Price); } ...

Write to a File in Monotouch

How would I create and write to a file in a Monotouch iPhone app? The file should persist between application launches, so I guess it has to be placed somewhere in the App bundle ( documents or resources?). ...

How to most elegantly iterate through parallel collections in C#?

var a = new Collection<string> {"a", "b", "c"}; var b = new Collection<int> { 1, 2, 3 }; What is the most elegant way to iterate through both yielding a set of results "a1", "b2", "c3"? ...

.Net How to get notified efficiently when a thread is suspended?

Hi, Does anyone know a way to get notified when a specific thread is being suspended and resumed? I would like to be able to to something like this: thread.Suspended += delegate { //Do something }; thread.Resumed += delegate { //Do something else }; I doubt that the .Net Framework has this capability, but is there a techniq...

Is using get set properties of C# considered good practice?

Hi, my question is simple, is using the get set properties of C# considered good, better even than writing getter and setter methods? When you use these properties, don't you have to declare your class data members as public ? I ask this because my professor stated that data members should never be declared as public, as it is considered...

PNRP - How does it work?

Sorry if this seems like a stupid question but im actually having a hard time finding a straight answer. I know PNRP is MS's technology for implementing peer-to-peer but how does it actually work - i mean im assuming when you register your address in the global cloud that it is actually contacting a Microsoft server to find a peer addre...

How to deploy C# code to a server? How to run an exe on a server?

Th short story is: I have a Godaddy shared Windows server account and I have some C# code on my computer that runs perfect locally. I want to run this code on the server as an exe file. Is this possible? I do not believe I have command prompt or remote desktop access to my shared space. More details: The end goal is to have a website wh...

Need advice for building a search in an ASP.NET MVC application.

I've been googling but haven't found any good info on building a good search function in a ASP.NET MVC project. Off the top of my head, a search feature for searching authors and books would look like this: char[] delimiterChars = { ' ', ','}; string[] searchterms = SearchBox.Split(delimiterChars); IQueryable<SearchResult> SR = _db.Boo...

How do I create a binding that involves some sort of formula?

As an example, if I have an element whose size I want to be twice the size of another element, how would I achieve this? An example would be the following, mirroredObject is the object that I want to use half of it's width for the width of the Border object. <Border Width="{Binding ActualWidth, ElementName=mirroredObject, Mode=Default}...

How do you extract an assembly full name from the assembly qualified name of a type?

I have an assembly qualified name of a type, e.g. MyNamespace.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null I want to extract the assembly full name, i.e. MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Obviously I could do this with simple string parsing, but is there a fr...

What technology stack to choose

Hi, For the criterias below, what a technology stack would fit best? Cross-platform (Linux/Windows). Ability to run as a service (daemon). Powerful object-oriented data access (O/R-mapping). Multiple databases support (MsSql, Oracle, MySQl, SqlLite, Postgress). Web application can be tested (Unit and Integration testing). Reasonable o...

C#: Unable to Bypass Cache (WebClient)

WebClient Client = new WebClient(); Client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); Why is this code above not actually preventing sites from being cached through the .Net Web Client? ...