Click here to Skip to main content
15,891,136 members
Everything / Programming Languages / C# 4.0

C# 4.0

C#4.0

Great Reads

by Igor Ladnik
Wrapper to facilitate usage of TCP sockets
by Sacha Barber
It would probably be like Cinch, an MVVM framework for WPF.
by Roman Kiss
This article describes a design, implementation and usage of the Custom Routing Manager for managing messages via Routing Service built-in .Net 4 Technology.
by Adam David Hill
All the juicy tricks and scandalous shortcuts which helped us ship our competition game on time

Latest Articles

by Elmue
An easy to use 3D control which can be integrated into an application in a few minutes
by NikStar
Using OutgoingMessageProperties and OperationContextScope to implement authorization by http header for WCF client that communicates with non WCF-based web services.
by Siddhartha S.
WPF smart client demo of nitty gritty of MVVM for a real life LOB application
by Shivprasad koirala
Understanding two terminologies - reflection and dynamic keyword

All Articles

Sort by Title

C# 4.0 

16 Apr 2011 by RamyaShivraj
Hello,How do I overcome the "Could not import all the messages" from FxCop tool?I have added few a targets to the FxCop project (Fxcop 1.36 and WPF project) and analyzed.Then a few warning messages have been excluded and saved the fxcop project.Now every time the fxcop project is...
16 Apr 2011 by Anil_Saran
Hi,Kindly follow the below link,As it seems to adjust some project property setting.http://msdn.microsoft.com/en-us/library/bb429341(VS.80).aspx[^]However even after this problem still persist then you can send me the sample on saran.anil@hotmail.com :)Regards,Anil Saran
16 Apr 2011 by #realJSOP
FX-Cop merely provides guidelines. If your code compiles and runs, you don't really have to do anything except fix bugs.
23 Mar 2015 by Oleg Shilo
The extremely simple implementation of generic "Extension Properties"
24 Jun 2009 by kcs2c
This demo allows you to verify that you have a valid key and can format a request..
21 Jan 2013 by zqliu
f1(), f2(), f3() is a function of type bool, which of the following style is better? A. if (f1 () && f2 () && f3 ()) do (); B. if (f1 ()) if (f2 ()) if (f3 ()) do ();If three function execution time is longer, is B method is better? Or they are just the same...
21 Jan 2013 by PIEBALDconsult
They should be about the same. I prefer A; it's more polished. Any fool can do B.
21 Jan 2013 by nv3
It actually doesn't matter from a run-time point of view. In other words, A and B will run equally fast. For readability purposes, however, I would always prefer A. or better yetif (f1() && f2() && f3()) doSomething ();
21 Jan 2013 by Abhinav S
I'd prefer A. If (f1 () && f2 () && f3 ()) do (); because it is much more clearer and easier to understand.You are using && which is a short circuit operator.If the first condition fails the second won't execute so there will be no difference in execution time in either case.
21 Jan 2013 by Andreas Gieriet
You left out a 3rd variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}and a 4th variant:bool hasSomethingToDo = f1() && f2() && f3();if (hasSomethingToDo){ DoSomething();}Usually,...
21 Jan 2013 by H.Brydon
Any C/C++ compiler nowadays will treat both the same way and generate either the same code or almost the same code.A point perhaps more important than performance for this one-liner is maintainability. In most cases, 'A' is the better choice - if the logical tests are truly function names or...
26 Mar 2015 by Wasim1989
HI experts,In my code I am creating excel file using OpenXml, in local environment it works fine(even with large data) but when I generate same file on production it gives me error like "Initialization failed" when excel data more than 100 KBs. I searched on net and get solution like...
26 Mar 2015 by Mario Z
Hi, I cannot be 100% sure, you really did not provide much information, but I believe your solution is not using the IsolatedStorage, you see your issue ("Initialization failed") occurs due to it.Unfortunately you don't have a control over this, the OpenXML SDK uses System.IO.Packaging...
7 Dec 2011 by kunal naik
Hi,I am using following link to make a report,Generate a Report using Crystal Reports in Visual Studio 2010when I was add a table on report viewer and run my project then it will get anerror "Load report failed" on following...
7 Dec 2011 by koolprasad2003
check out following linkCrystal Reports: Fix for "Load report failed" error.[^]
8 Dec 2011 by thatraja
Already answered similar question(s), check thisLoad Report Failed in Crystal Report[^]Load Report Failed[^]EDITCrystal Reports: Fix for "Load report failed" error.[^]
14 Apr 2011 by vithalgk
Hi all,I am trying to create the new project type by following the "Walkthrough: Part 1 - Creating a Basic Project System" but in between i got strucked in place of "Locate the managed project source files by following this link". Please give me path from where i can download "managed project...
14 Apr 2011 by OriginalGriff
If you mean the MSDN walkthrough Walkthrough: Part 1 - Creating a Basic Project System[^] Then I would click the link. It takes you to here: http://mpfproj10.codeplex.com/[^]Which directs you to the Source code tab here: http://mpfproj10.codeplex.com/SourceControl/list/changesets[^] Which...
26 Apr 2011 by vithalgk
Hi OriginalGriff,Thanks for responce but I allready tried those options and not able to proceed at all. those downloads are not usefull. I searched lot to solve the problem, but nowhere no answer. Please suggest me the solution.ThanksVithal
19 Mar 2013 by Rohith Reddy Vadiyala
Hi,I'm importing excel 2013 data to database. but it is raising the following exception "Microsoft.ACE.OLEDB.12.0 is not registered on local machine"I'm using MS Office 2013, VS 2012, SQLSERVER 2008 and Operating System is Windows8Here is my code.. string filePath =...
19 Mar 2013 by Maciej Los
Try to fix it as is described here: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/f11b2df9-fd0a-4528-987f-f95dfdccee0a/[^]
20 Mar 2013 by Rohith Reddy Vadiyala
All we need to do is Install AccessDatabaseEngine in our system then it works like charm..
14 Jan 2013 by CafedeJamaica
I am getting and error that the "safe handle has been closed" when my code is running.I have a code block in my function with a "using" statement and on some of the variables I get the exception that the variable has been disposed.When I call the function the first time it runs fine but...
14 Jan 2013 by Tharaka MTR
Yes, I'm agreed with a comment, shared desen't contains enough information. I tried to simulate this, but my code works fine.I guess, the error you mentioned is occurred with var pkCert = _CertFile.PublicKey.Key;using(var rsaCryptoServiceProvider = (RSACryptoServiceProvider)...
2 Sep 2012 by khosro goudarzi
HelloI used this code for write to Resx embedded file. Assembly assembly = Assembly.LoadFrom(@"ClassLibrary2.dll");Stream stream = assembly.GetManifestResourceStream(@"ClassLibrary2.defualt.resources");ResourceWriter rw = new ResourceWriter(stream);rw.AddResource("welcomeString",...
2 Sep 2012 by Mehdi Gholam
Manifest resource streams are readonly and cannot be written to this way.See the following : http://www.c-sharpcorner.com/uploadfile/yougerthen/handle-resource-files-read-and-write-into-a-resource-file-programmatically-part-iv/[^]
2 Sep 2012 by _Amy
Hi,Refer the links below for the similar threads:possible causes for stream not writable exception?[^]Cannot write to file after reading[^]https://groups.google.com/forum/?fromgroups=#!topic/dotnetdevelopment/r-s7PHfOiPc[^]--Amit
4 Jul 2012 by .net333
hi friendz, i am getting the huge amount of data(Contacts) from Sql server..i am getting the following error...Error:An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/ICloudServices/ContactService/. This could be due to the...
5 Jul 2012 by Libish Varghese Jacob
Here this kind of exception can happen if your receiveTimeout is not large enough.Here in your configuration, you are setting receiveTimeout="05:00:00" in "binding name="basicHttpBindingSettings" " but you are not associating it with your end point. Either remove the name attribute from the...
28 May 2014 by Member 10532069
protected void btnView_Click(object sender, EventArgs e) { BA.DeptNo = int.Parse(txtno.Text); BA.option = "select"; DataTable dt = BA.viewRecords(); txtname.Text = Convert.ToString( dt.Rows[0]["dname"]); ...
23 May 2014 by OriginalGriff
I suspect your code doesn't look like that - Visual studio would have tidied up the indentation for you - so it will really depend on what your real, executing code looks like: I don't think you have the dt.Rows.Count>0test in the "live" code, as the only way it should get to the row access is...
24 May 2014 by DamithSL
Add validations as belowprotected void btnView_Click(object sender, EventArgs e){ BA.DeptNo = int.Parse(txtno.Text); BA.option = "select"; DataTable dt = BA.viewRecords(); if (dt!=null && dt.Rows.Count >0) { txtname.Text =...
24 May 2014 by Member 9444634
use below validation before your line which is throw error :if (dt!=null && dt.Rows.Count >0)
24 May 2014 by Volynsky Alex
Please read these things...
28 May 2014 by swati0725
protected void btnView_Click(object sender, EventArgs e){ BA.DeptNo = int.Parse(txtno.Text); BA.option = "select"; DataTable dt = BA.viewRecords(); // Before using table object, should check of null reference if (dt != null && dt.Rows.Count >0) { ...
19 May 2015 by Member 11445380
Please Help me Its way too urgent!!!and i need to store images itself not their pathI have the requirement to save image into Database.Description of my question is : I have a asp.net 4.0 web application that uploads a image and then my application converts that image into byte...
20 Jan 2014 by Rajib Mahata
CREATE PROCEDURE `FetchSupplierByRequest`(intConferenceId int, intRank int,intTableNo int)BEGINSELECT Distinctc.ID , c.CompanyName,c.TypeFROM conferencetabletop cp, companies c,meeting mWHERE cp.ConferenceID = intConferenceId AND c.ID = m.SupplierIDand...
22 Jan 2014 by idenizeni
According to the information I can find, older versions of MySQL cannot use variables in the LIMIT clause and constants must be used. Similar issue posted to StackOverflow with some useful information.http://stackoverflow.com/questions/2875238/passing-limit-as-parameters-to-mysql-sproc[^]
28 Aug 2015 by Sergey Alexandrovich Kryukov
The idea is correct. The problem could be the timing: your main form is showing on background later than the capture. You may need to to the following: show the form in background and then use Control.BeginInvoke to delegate the capture, so it could be taken at later time.—SA
31 Jul 2015 by binadi007
Hi,I'm facing a unique problem of firefox and i.ewhen I passed a function from $.AJAX with datatype as JSON then that function (provided in url with some parameter) will not executeNote :- I'm using both onclientclick event and button click event on the same buttonAnd when I'm...
28 Jan 2013 by jayeshkumar.rathod
hello everyone i wrote following sentenceint temp = 7 & 9;it returns 1..can anybody explain it how.?
28 Jan 2013 by CPallini
Because the & operator performs bitwise AND operation between its operands: 9 & 7 = 1001b & 0111b = 0001b = 1Remember, the truth table for AND operation is &01000101
19 Nov 2014 by Member 10496208
string filePath = (sender as LinkButton).CommandArgument;Response.AppendHeader ("Content-Type", "Application/octet-stream");Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath) );Response.WriteFile(filePath);Response.End();
4 Aug 2015 by AMIT GAWDE
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e) { invoice.dg1.Rows.Add( DataGridView3.Item(0, e.RowIndex).Value, DataGridView3.Item(1, e.RowIndex).Value, ...
4 Aug 2015 by ZurdoDev
You'll have to change it to C#. There are online tools to translate that you can google for but if this is all the code you have, I suggest just retyping it in C#.
24 Nov 2014 by itsathere
public HttpResponseMessage Delete(string strApiKey){ string strDomainName = PageUtility.GetCurrentDomainName(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(strDomainName); // Add an Accept header for JSON format. ...
27 Nov 2013 by Siva Hyderabad
I want to know why Type 'iTextSharp.text.Table' is not defined. I already imported iTextSharp.text , iTextSharp.text.pdf, iTextSharp.text.html, iTextSharp.text.html.simpleparser.
27 Nov 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Refer- Type 'iTextSharp.text.Table' is not defined[^].Quote:In searching the Internet the only thing I could find about iTextSharp.Text.Table was example code. I looked at the SVN on SourceForge and there is no Table that is part of the text namespace, it looks like it was depricated in the...
17 Dec 2012 by pranathis012
Hi,My PC configuration 64 -bit formate and MS- Office formate is 32 - bit formate. And i install AccessDataBaseEnginee also 32 bit formate . Then also i'm facing the same problem 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. can anyone help me to resolve...
14 Dec 2012 by Krunal Rohit
http://social.msdn.microsoft.c...
19 Jul 2013 by StackQ
While working with Microsoft Access Database connectivity with with ADO.NET you might have received this error The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine The 'Microsoft.Jet.oledb.4.0' provider is not registered on the local machine etc...
19 Jul 2013 by vinaykn.rao
http://sharepointtweets.blogspot.in/2013/07/read-each-worksheet-from-excel-file.html[^]
19 Jul 2013 by Shambhoo kumar
Quote:Hi,I think this issue is caused by you are running 64-bit windows and there are no MS Access drivers that run 64-bit. So I suggest you trying to change your build configuration to x86. You can do that on the project properties dialog under "Compile>Advanced Compile Options...>Target...
8 May 2014 by sanjeevka08
install office 2007 in your system. Not later or previous versions
23 Sep 2011 by Anele Ngqandu
Hi guys am populating a gridview according to selected dateI get this error:DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FullName'.this how i populate #region Load grdAvailableStaff Slots When Date Is Selectedpublic void...
23 Sep 2011 by Simon Bang Terkildsen
I'm guessing you're binding to FullName in your grid, yet FullName is not a column in your query
16 Aug 2018 by srmohanr
Hi I am getting the error in my C# Console application'System.IO.Stream' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.IO.Stream' could be found (are you missing a using directive or an assembly reference?)This...
9 Jan 2014 by Karthik_Mahalingam
Hi mohanCopyTo is available in dot net Framework 4.0 and above only.Reference:System.IO CopyTo[^]Please change your project version to Framework 4.0. Right Click Project -> Properties - > Application Tab - > Target FrameWork -> select .Net Framework 4.0
28 May 2014 by ftosteve
And what if you have to target .NET2?Changing the project to .NET4 is just cheating...
28 May 2014 by CHill60
Apologies - I know this is an old post, but as pointed out by ftosteve[^] (in a solution that may be deleted) ...Quote:And what if you have to target .NET2? Changing the project to .NET4 is just cheating...This blog[^] from Sam Beauvois gives examples that will target frameworks
21 Jan 2010 by aasifaslam
hi ,Please can anyone help me ?i m trying to call a function say getdevice();which is present in my unmanaged dll. the function in dll has parameters say getdevice(char **pDeviceList,int *pDeviceCount, unsigned longulFlags)actually i m using c# and doing coding in c# as well and my dll...
21 Jan 2010 by J a a n s
You can call your unmanaged methods using PInvoke. Check the folllowing articles for details.http://msdn.microsoft.com/en-us/library/aa446536.aspx[^]http://msdn.microsoft.com/en-us/magazine/cc164123.aspx[^]
8 Jan 2015 by shaliniraji
Hi everyone,I've created 1 windows app in that app i've created Registration form including image fields.After filling all the details in that form when i click on save button i'm runtime error(Failed to convert parameter value from a Bitmap to a Byte[])..Can anyone tell me how to resolve...
7 Jan 2015 by OriginalGriff
Um...The only thing you use the array of bytes for is to get it's length:byte[] photo = GetPhoto(imageloc);... SqlParameter p17 = new SqlParameter("@Vehicle_Pic",SqlDbType.Image,photo. Length);SqlParameter p18 = new SqlParameter("@Customer_Pic ", SqlDbType.Image,...
27 Mar 2012 by SvenMe
Good morning everyone,I recently started playing around with Metro Apps. I came up with a tiny music player. Unfortunately there is one problem.I've the following code:private static readonly object Locker = new object();private static volatile BitmapImage _defaultCover;...
1 Apr 2012 by maxhmreid
I also have this problem. In my case I am receiving data from a WiFi webcam.I have managed to improve it quite a bit by replacing a blocking network call for the async version, but the image still flickers like crazy.My networking call and bitmap generation only take around 5 milliseconds...
19 Dec 2012 by Oleksandr Kulchytskyi
Hi guys.I have one question about disposing resurces.for event observation i use Rx(Reactive Extensions).Observable.FromEventPattern(_outlookManager, "MailReceived", Scheduler.ThreadPool). ...
17 Feb 2014 by Jon Joeney
Hi, I thought I understood LINQ according to my book. I don't.All I want to do is sum some numbers. My code is below. The bit that doesn't compile is obvious.My question is what am I doing wrong? All I want to do is sum the numbers 1 + 2 + 5 - 1000 + 100 = -892 but I can't even do that....
17 Feb 2014 by Serge Desmedt
I think Baz.Select returns a list of lists, nl. a list of Bar (which is a list) ant the lsit does not have property FooHave you tried SelectMany ?
17 Feb 2014 by Jon Joeney
Hi Serge, yes I tried SelectMany too, code below:var resultSum = c1.Baz.Select(x => x.Bar).SelectMany(y => y.Foo).Sum(z => z);I cant get this to compile either so although I think the syntax is correct, it clearly is not.
17 Feb 2014 by Vedat Ozan Oner
you can do it like that:var resultSum = c1.Baz.SelectMany(x => // selecting all Bars as one IEnumerable x.Bar).Sum(x => // summing all Foos. x.Foo);ps: please send your comment as comment, not a solution.
18 Oct 2011 by shashikanth 2011
protected void btnSendmail_Click(object sender, EventArgs e) { // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0 // System.Net.Mail.SmtpClient is the alternate class for this in 2.0 SmtpClient smtpClient = new SmtpClient(); ...
11 Mar 2012 by Mehdi Gholam
Sending emails to Google's server require you to be on port 587 using EnableSSL=true and to be authenticated first on Google ie with an account ending in @gmail.com etc.[edit]Changed 589 to 587[/edit]
11 Mar 2012 by Aniket Yadav
For Gmail Account SMTP, disable 2 step verification and send email.Also refer this from codeproject articleSending an Email in C# with or without attachments: generic routine.[^]
20 Sep 2016 by ebsen
You need a html to pdf converter and there are plenty of such libraries for .net but you need one which supports partial conversion of a html region to pdf because you want to convert only table inside a HTML page. A good solution is based on hiqpdf at convert a part of html to pdf . Only the...
3 Mar 2015 by Member 10556393
In gridview template field,(TextBox)e.Row.FindControl("TextBox13") = ?How to assign values for this from datatable.
4 Mar 2015 by Praneet Nadkar
Hi,Try this://DataTable ObjectDataTable dt = new DataTable();//Find textbox controlTextBox txtId = (TextBox)e.Row.FindControl("txtId");//Lets say u want the data from the first row. U can use loop hereDataRow dr = dt.Rows[0];txtId.Text = Convert.ToString(dr["ColumnName"]);
6 Jun 2013 by VIP Venkatesan
Hi friends, i've two pages "search.aspx" & "View.aspx".Search.aspx contains one gridview with columns "Name, College","DepartMent" Select NAME COLLEGE DEPARTMENT CBox AAAAA BBBBB CCCCC CBox ...
6 Jun 2013 by Rashmikants Monpara
You create New Div and Create this Name : AAAAA , BBBBB , CCCCCCollege : BBBBB , CCCCC , AAAAADepartment: CCCCC , AAAAA , DDDDDand after click search button this div are visible true and view page dive are visible false so your problem solve
6 Jun 2013 by Thanks7872
Absolutely possible. First you bind your data to gridview on Page_Load Event as follows:protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { //Bind your gridview here. }}Now you have gridview with four columns...
6 Jun 2013 by VIP Venkatesan
I've Tried this one.. but not satisfied.protected void lbassettransfer_Click(object sender, EventArgs e) { foreach (GridViewRow gvrow in GridView1.Rows) { CheckBox chkdelete = (CheckBox)gvrow.FindControl("cbselect"); if (chkdelete.Checked) ...
10 Feb 2013 by Eljeddi
hello everybody....I'm a student and i need some ressource about the .net development,,, wcf,wpf,c#,VS,ASP.net,sql server... i'm looking for books and tutoriels and everythings can help me as a beginner ,,thank you in advance :)
10 Feb 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
As a beginner, I would suggest you to go for MSDN articles and try the examples given there. When you will start building some sample applications, if you face any problems, then just come back to this awesome Technical Forum Code Project with your question.Everybody will help you here.For...
8 Jun 2012 by Clifford Nelson
First of all, the code seems to work fine. Don't know what your problem is. I changed the file type I was looking for to ".cs" since I have no .acc. Also since you were bothering with the list of files (Filenames) instead of Filename, I set multiselect to...
8 Jun 2012 by mane0806
when i open dialog box to select audio file's everything except ".acc" can be seen and selected.. Following is my code.. { System.Windows.Forms.OpenFileDialog os = new System.Windows.Forms.OpenFileDialog(); os.Filter = "Audio...
1 Feb 2014 by Member 10537453
Hi all, In html 5 there is "Date" input control.I want to get the value of the selected date in .cs file can any one help me how can i do it.ThanksSamar
1 Feb 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Refer - Render asp.TextBox for html5 input type=“date”[^].
1 Feb 2014 by Abhinav S
Try http://www.w3schools.com/aspnet/prop_webcontrol_calendarday_date.asp[^].
1 Feb 2014 by CoderPanda
Hi1. Either you declare the Date control as Server ControlOR2. Place the control in a form so that you can access it via the request object on the server side.[Please encourage participation by up-voting solutions or answers that work for you]
1 Feb 2014 by JoCodes
Date Input Control declaration,Can access it server side likevar control = Request.Form["Calendar"];Note: Not sure here why runat=server attribute doesn't work.
4 Nov 2022 by fdiu
class Program { static void Main(string[] args) { int first = 10; int second = 20; int third = 30; int forth = 40; int fifth = 50; } }.method private hidebysig static void ...
25 Oct 2012 by Keith Barrow
Had to look this up, I've written precisely 0 lines of IL, but your question is interesting:.maxstack is the maximum evaluation stack depth/height, going through the IL, you only have a mamximum of 1 thing on the evaluation stack:.locals init ([0] int32 first, [1] int32...
4 Nov 2022 by Eduard de Jong
Very late reply here, but that's just because I'd like to add some useful information for those finding this article by googling. The .maxstack has indeed nothing to do with the .locals, which are part of the method stack and not the evaluation...