Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17







C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

Share tech news, updates, or what's on your mind.

Sign up to Post


I want to know how to remove temp files after Response.End

If I add File.Delete(prcss_docPath) in the finally the download does not complete.

        string srcTemplate = String.Empty;
        string prcss_docPath = String.Empty;
        string dnNo = String.Empty;
             srcTemplate    = "FileSrc.docx"
            prcss_docPath = "File.docx";
            bool processed = false;
            File.Copy(srcTemplate, prcss_docPath, false);
            ContractProcess cps = new ContractProcess();
            processed = cps.ParseWordTemplate(prcss_docPath, dnNo);

            if (processed)
                 FileInfo file = new FileInfo(prcss_docPath);
                Response.ContentType = "Application/msword";
                Response.AppendHeader("Content-Disposition", "inline; filename=" + file.Name);
                Response.AppendHeader("Content-Length", file.Length.ToString());
        finally //Delete the files.


Open in new window

New feature and membership benefit!
LVL 10
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

assume i have xml file call abc.xml

do you know any plug-in or app in c#/aspx.net that will create step by step form wizard based on the xml structure.
below we will start to read 'Notary' & 'CA' then i should have three steps

I just need some sort codes example to start.

          <Bond Name="Notary">
            <State name="CA"> 
              <Principal step="Step 1">
                <input type="text" class="" id="principalFirstName" placeholder="First Name" value=""></input>              
                <input type="text" class="" id="principalLastName" placeholder="Last Name" value=""></input>
                <input type="text" class="" id="principalMiddleName" placeholder="Middle Name" value=""></input>
                <input type="text" class="" id="principalCompanyName" placeholder="Company Name" value=""></input>
                <input type="text" class="" id="principalDBA" placeholder="DBA" value=""></input>
                <input type="text" class="" id="principalAddress" placeholder="Address" value=""></input>
                <input type="text" class="" id="principalCity" placeholder="City" value=""></input>
                <input type="text" class="" id="principalState" placeholder="State" value=""></input>
                <input type="text" class="" id="principalZip" placeholder="Zip" value=""></input>
                <input type="text" class="" id="principalPhoneNo" placeholder="Phone No" 

Open in new window

we want to see anyone has been developing web form /c# with edmunds api. They do not have .net/c# sample.
Assume we have <asp:net dropdown> and I just need to bind their car maker, model, and year.

c#, asp.net
I'm working on consuming a third party web service. I know there are couple of ways to consume a web service. I tried following ways

1. I used visual studio to add a service reference - using this method, I have access to and declare a proxy/client object for the service, like below and set the credentials.

    ABCService proxy = new ABCServiceClient();

    proxy.ClientCredentials.UserName.UserName = "username";
    proxy.ClientCredentials.UserName.Password = "password";

2. I used WSDL.exe tool to generate a proxy class manually. After including the proxy class in my project, I have access to the object and properties in the proxy class, but I can't declare a client object like in step one and set the credentials.  
Questions -

1. how to set up UsernameToken element (WS-Security standard) in the soap header when generating a proxy class manually like in method 2 above.

2. what are key differences between method 1 and 2?

3. Also, is there any difference between using WSDL.exe vs SVCUTIL.exe?
Hi Experts,

I am generating some labels as shown in Label1.png. My design is in Labeldesign.png.  My client needs the output in two columns as shown in Label_Desired.png. Please suggest is there any way to do it?

Thanks in advance.
So, I can access a file server in the network, I was given a login credentials- username and password.
I will specifically use this login/pw to access files in a server to allow reading and writing to this particular folder.
Windows authentication is used to login to the app.

I would like to switch to this  ID/pw given to me to authenticate and authorize writing and reading files to the server.

How would I sign in to this identity when I have to write and read files to this particular server? And then when I'm done, Ill switch it back to my original id/pw  identity?

I want to set Target Framework as .NET Standard 2.0 for my new .NET project. Where can I find the download so that I an install n my machine and use for new projects with .NET standard 2.0 as target .

Please se the attached,

Troubleshooting a piece of code.
            Dim web As Net.WebClient = New Net.WebClient()
            Dim html As String = web.DownloadString("https://www.google.com/finance/converter?a=1&from=EUR&to=USD")
            Dim m1 As Match = Regex.Match(html, "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline)
            Dim currency As String = m1.Groups(1).Value.Replace("USD", "")


Open in new window

currency is blank.  

My question is what does "<span class=bld>\s*(.+?)\s*</span>", RegexOptions.Singleline" do?
I keep reading you can do C# on SPO (sandboxed solution). I make a small webpart that says hi, it deploys to my development site with no errors, but it doesnt look like it installs the feature. What gives ?
I then find an article that you can't do sandboxed soultions https://blogs.technet.microsoft.com/marios_mo_betta_blog/2016/08/02/sharepoint-online-sandboxed-solutions-disabled/
In this article in mentions how to do it anyway (I think ?) https://support.microsoft.com/en-us/help/3183084/remove-the-assembly-reference-from-your-sandbox-solution-created-in-vi
Can someone tell me if you can write a C# visual web part for SPO ? Definitavely ? I have to present this to management and I want to be correct.
I am working on a .Net application that is using nHibernate and I am passing through a structured datatype into a stored procedure.

I am using an extended method like this

    public static class StructuredExtensions
        private static readonly Sql2008Structured structured = new Sql2008Structured();

        public static IQuery SetStructured(this IQuery query, string name, DataTable dt)
            return query.SetParameter(name, dt, structured);

Open in new window

The full code of this is in the attached file,

The SQL User Defined Table Type is

	[PRNCPL_ACC_CD] [char](10) NOT NULL,
	[BRANCH_ACC_CD] [char](10) NOT NULL,

Open in new window

Free Tool: Subnet Calculator
LVL 10
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

i have a two serially (COM1->COM2) AND (COM2->COM1) connected USB device . i transmit the information into com1->to com2 same-way to second device .  but i want  to disable/enable  device when its running period .  i am trying to solve this problem but when   i am running the code exception will occurred (" data is invalid" ) . how to solve this problem?
Hello Experts,
In a Windows Service program, I am trying to delete a file.  It works fine in my machine.  For example if the file is found, my program  deletes it and if the file not found, I get exception.  Same program when copied to production, neither the file gets deleted, not do I get any exception.  I am sure it goes to delete portion of the method.  Because I tested it with log4net.  FYI, in development I am using Windows 7 Pro and in Production Windows Server 2008 R2.  Any idea?  Below is my code.  Please help.

Thank you in advance.

public void DeletePMTFile()
            string fullName = System.Configuration.ConfigurationManager.AppSettings["FULL_NAME"];
            string filePath = System.Configuration.ConfigurationManager.AppSettings["FILE_PATH"];
            var reader = new StreamReader(fullName);

            FileInfo fileName = new FileInfo(fullName);
            if (File.Exists(fullName))
                    Array.ForEach(Directory.GetFiles(filePath), File.Delete);
                catch (System.IO.IOException e)
                    log.Error("DeletePMTFile: Error while deleting the file" + e.Message);
                log.Warn("DeletePMTFile: " + filePath.Trim() + " not found");

Open in new window


 Im using datagridview in c#. when i add a new row in datagridview programmaticlly it shows error like "operation did not succeed successfully because program not commit or quite cell value change. but remember it shows error when i remove first item of datagridview and add new row again
here is code to add item in datagridview DataGridViewRow row = (DataGridViewRow)dgInvcProductList.Rows[0].Clone(); row.Cells[0].Value = productID; row.Cells[1].Value = name; row.Cells[2].Value = Detail; row.Cells[3].Value = Size; row.Cells[4].Value = Sale_Price; row.Cells[5].Value = Quantity; row.Cells[6].Value = totalPrice.ToString(); row.Cells[7].Value = Sale_Unit; dgInvcProductList.Rows.Add(row); First ImageAfter remove first rowWhen i add new row again error occure
I have written a big C# program, (like 84 pages long), and I want to use GNU grep to compile a list of all of the C# symbols, such as variable and class names into a .csv file for the purpose of creating a "data dictionary" that accompanies the program so that I can continue to maintain programming it effectively.

Somebody please tell me how to compose the pattern expression that does that. Or if there is a tool expressly for doing that, please tell me what the name of that tool is. (preferably a free tool).

I can successfully write to the MS message queue by doing this:
using (MessageQueue alertsQueue = new MessageQueue(Program.alertsQueuePath))
                    BinaryMessageFormatter formatter = new BinaryMessageFormatter();
                    System.Messaging.Message message = new System.Messaging.Message(this, formatter);

                    alertsQueue.Send(message, "CommonObject");

Open in new window

where "this" is a class called clsCommon.cs and is a populated object with values

Then on another console app, i need to read this message and i guess deserialise it
   public void MqReceiveCompleted(object sender, ReceiveCompletedEventArgs e)

                clsCommon objClsCommon = new clsCommon();
                string strObjClsCommon = e.Message.Body.ToString();

//here is need to convert the string I just got into objClsCommon

Open in new window

any ideas?
Hi All

I have the following applications

1. Web app (asp.net)
2. TCP importer windows forms app (imports data from gps devices in cars)
3. Translator console app - takes messages from MS Message Queue and puts in SQL DB
4. Alerts console app - takes messages from a different Message Queue and sends sms/emails

all have different teams, and with excepting of web app, all are having to store in memory little objects to speed up performance instead of doing DB lookups
We are processing 100 records a second (and it will keep growing), so we have to have stuff like a key value pair in memory (i.e. ImeiNumber, DB ID)

As each app has its own implementation of an in memory dictionary, and there are lots of them which all do different things, but ultimately storing the same data, I was thinking of a distributed memory cache, or some sort of API where it returns the data instead of doing a DB lookup
I think an API will be heavier, and currently apps 2,3and4 are on same windows 2016 server

I've been looking around and found memcache and memcacheD
However, it seems quite related to php etc, and not .net
I was wondering if there are are pure .net alternatives
We are using framework 4.5

What would you do in my position, and have you had an real experience with this
I'm currently a bit overwhelmed with all the data online, and would value so guidance and advice of what to use
In this code I am having the following problem.  Let's say that soOnly.ship_instruction_1 (which comes from a SQL view) is null, but OrdsToSend.ship_instruction_1 does not allow nulls.  At SubmitChanges it is going to fail and fall into the catch block.

When we move to the next order in the foreach and it reaches SubmitChanges, the values from the failed sumbit persist in the OrdsToSend object.

Originally this was written so that we "new up" OrdsToSend for each order within the foreach.  We changed it to set OrdsToSend to null for each order and in the catch block, but that doesn't help.

How can I "clear" the OrdsToSend object so that it accepts the values from the next order?

By the way, the null is completely invalid and should error.  It cannot "legally" be replaced by an empty string.  That's why we don't bother to check for nulls on any of the columns.


 private void TestCode()

                dcMydc dc = new dcMydc(this._ConnString);

                IQueryable<string> ordList = (from i
                                              in dc.CS13000_SubjectOrders
                                              orderby i.ord_no, i.inv_no, i.line_no
                                              select i.ord_no).Distinct();

                foreach (string order in ordList)
                    CS13000_SendOrd OrdsToSend = null;

I'm using Razor but i'm not knowing it well (inherited project).


I'm using it to respond to a Twilio Conference Callback.  Twilio server send me a msg to tell me that a conference started/ended or participant joined/left, and no mather what i return in the <response></response>, it won't be executed.   But Twilio specifically request to return this empty response otherwise it trig a warning.

What i want to do

I would like to make one or more calls to external web pages to notify our services, and still return that empty response to make sure Twilio doesn't trig a warning.

Anyone can give me some help?

I've tried response.redirect in my callback, but of course, it doesn't return an empty response since and it's doesn't make Twilio Server happy.

Thanks for your help
I had this question after viewing Error 1053: The service did not respond to the start or control request in a timely fashion..

I have exact the same issue as above.  I installed the Windows Service, when tried to Start the Service inside the Services window I received the error message below.  I looked at the above link, but it did not help me.  Any idea why I am getting this?  Please help.  Thank you in advance.

Error 1053: The service did not respond to the start or control request in a timely fashion.

Thank you!
Concerto's Cloud Advisory Services
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

I'm using C# with Visual Studio 2010 Windows Form.  In my program this works.

string str="";
str = string.Format("{0,-18}{1,-12}{2,-15}{3,-18}{4,-15}{5,-18}{6,-8}{7,-18}{8,-15}{9,-16}{10,-14}{11,-60}", l_s_symbol.ToString(), s_l_WTIDX, s_l_PIDX, s_l_NSIDX,  s_l_MVIDX,  s_l_FMVIDX, l_s_ClassID, l_s_CLS1, l_s_CLS2, l_s_CLS3, l_s_CLS4,  SecurityName);

Open in new window

I'd like to get the formatting from an external file since I will be running the program for different processes each of which have different information.  For example something like this which has failed where the string ReportDetail comes from a config file.

string str="";
string ReportDetail="{0,-18}{1,-12}{2,-15}{3,-18}{4,-15}{5,-18}{6,-8}{7,-18}{8,-15}{9,-16}{10,-14}{11,-60}", l_s_symbol.ToString(), s_l_WTIDX, s_l_PIDX, s_l_NSIDX,  s_l_MVIDX,  s_l_FMVIDX, l_s_ClassID, l_s_CLS1, l_s_CLS2, l_s_CLS3, l_s_CLS4,  SecurityName
str = string.Format(ReportDetail);

Open in new window

I have a  asp.net site which contains a Create User Wizard.  Furthermore there is a Label on the outside of the Create  User Wizard.   I want the text  from the   asp:Label Id="txtCategory"    to  appear in the  asp:label "txtCategory1" in the Content Template of  Create User Wizard..  
Please help me with the best manner to have this happen at Page Load.


    <asp:Label ID="txtCategory" runat="server"></asp:Label>
<asp:CreateUserWizard ID="CreateUserWizard2" runat="server">
                                     <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server">
                                                     <td align="center" colspan="2"> <asp:Label ID="txtCategory1" runat="server"></asp:Label></td>
                                                     <td align="right">
                                                         <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
I am trying to do something similar to the app specs below.  I'm looking for a sample.  I thought I would use Asp.net Core MVC,  Ajax and SQL server.  I'm looking for a sample that can show me each step.

It's pretty simple.
1. My app has a form with 4 fields. (Vin, Make, Model, Year)
2. I input Vin in field 1 (Vin)
3. I GET from a third party Rest API JSON by passing the Vin to a URI string. The string will pass Vin I input and an API key
4. The API returns (Make, Model, Year)
5. I want to fill the additional form fields with (Make, Model, Year)
6. Finally, I want to save all fields (Vin, Make, Model, Year), to my Database.

I have been searching for an example similar.  I did find the Weather app example, but it's not complete.  It's just part of it.
Weather example: https://www.codeproject.com/Articles/1180283/How-to-Implement-OpenWeatherMap-API-in-ASP-NET-MVC
Hi experts,

I'm using ASP.NET MVC 5 with C#

On my view I have a DisplayFor displaying a datetime field.

My date time field is stored in sql server as datetime format

This is my current razor for this label on my page.

@Html.DisplayFor(m => m.MyTestDate)

With this syntax the browser displays this on my page.

07/17/2017 07:30:00 AM

Question 1: How do I format the razor DisplayFor tag to display only the date like this?:


Question 2: How do I format the razor DisplayFor tag to display only the time like this?:

07:30:00 AM
Hello Experts,
I am working on a Windows Service application in C#.  It is working fine in local machine.  I am getting the following error message when try to install in Production box.  I have set the Platform Target to Any CPU and Target Framework to .NET Framework 4.5. .  Also I tested it by changing the Platform Target to x86  and to x64.  But still getting the same error.  Please let me know how to fix it.  Thank you in advance.

Error Message
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///D:\Domains\XxxService\XxxPmtService.exe'
or one of its dependencies. An attempt was made to load a program with an incorrect format..

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>installutil -i D:\Domains\XxxService\XxxPmtService.exe
I have a Dymo .label file which is XML code and contains the code required to produce a label on a Dymo Labelwriter 450 printer. I need to convert this XML file to PDF so that I can send it to www.PrintNode.com via an API so that I can print it Clientside. PrintNode will only except a PDF file. In my Server application I have copied the XML code out of the .label file and inserted into into a PDF file using iTextSharp as shown below.
The outcome is that I get a valid PDF file but when I open it , it contains the XML code from the .label rather than the formatted Label which I was expecting to see.  I am obviously missing some part of the conversion process but don't know what it is. Needless to can that if I send this file to printNode it will just print the XML text rather than the label. Any suggestions or pointers or examples would be welcome.


C# Code where I insert XML into PDF document                          
                           // Create new pdf file
                                fs = new FileStream(filePath1, FileMode.Create);
                            catch (Exception ex)

                            //To create a PDF document, create an instance of the class Document and pass the page size and the page margins to the 

Open in new window







C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).