C#

92K

Solutions

25K

Contributors

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'm using goDaddy to host a website and need to do a file upload into a table. It occurred to me that I don't think I'll be able to use excel as my data source so I was hoping to be able to upload a .csv file. Is there a C# example of how to do this or possible some other method?
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I have an installshield program that works fine in terms of saving local files, data files registration information but with previous installations of the product (not controlled by Install shield)  those files are deleted during the reinstall
0
step one.
when user get token it call a c# class and returns the token.
step two
after the program get the token value uses a  html form post to send to an html page with a hidden value

How do i do this without a submit button.

The html code

 <form runat="server">
         <asp:Button ID="GetToken" runat="server" Text="Get Token" OnClick="GetToken_Click" />

   </form>
   
    <form method="post" action="https://test.authorize.net/payment/payment"
id="formAuthorizeNetPage" >
       
        <input type="text" name="Token" value="<%=token%>" />
       
         <input type="submit" name="button" value="Buy now" />


   
</form>
0
I had this question after viewing asp.net repeater modal & data command.
0
I have a table with the following columns
Ticket Number
Assignee

There is a separate table listing all assignees - something like a list of all the staff.  Each ticket can have multiple assignees.  Assignees can work on multiple tickets.

When the user selects a ticket I want a list box to show total staff with the assignees on that ticket highlighted.  The user should be able to add and remove assignees from a given ticket.  The list of selected assignees need to be passed to an SQL stored procedure.
I'm using C# in Visual Studio 2010.
0
I am trying to update an web refence url and get the folloring error in the attached file.
The current locataion is D:\DotNet\schemas\XAV.wsdl
the code was downloaded from ups and i need to change it to a local drive for testing which is
C:\Users\Ron\Documents\upsaddressaug\Street Level Address Validation for SHIPPING\XAVWebServices\SCHEMAS-WSDLs
i just seeing how the code works to use it
the program will not update the current location either.
error.png
0
Hello,
I am trying to create a branch within a branch, to do some development work and when I try and create the branch off of another branch, it gives me an error.
"No matching items found in //servername/branch on the server, or you do not have permission to access them.

Any clues?

I tried to look into the Build menu option on top of the TFS window but it wouldn't let me build a new definition, if this is needed.
"TF225000: You do not have permission to create new build definitions."

When I created the initial branch, it let me create that with no problems.  Why can't I create a branch off this branch?  Do I have to create a sub-folder and then point this branch to this folder or is there a better way to do this.  Or is it with the permission settings.

Thanks for the help.
0
hi want combobox in datagrid and do crud operation in wpf with EF.
0
I am working on a program in C# and WPF.  I have a ListBox control which has TextBox(s) added to it when an event is triggered.  I am trying to figure out how to set the Width of this TextBox to 100% of whatever the current area of the ListBox control is set to.  Does anyone have any suggestions on how to accomplish this?  Below is an example of my C# code that is run when the event is triggered.  Many thanks!

TextBox addTextBox = new TextBox();
addTextBox.Text = "Just Some Text";
addTextBox.Height = 25;
addTextBox.VerticalContentAlignment = VerticalAlignment.Center;
            
//This is where I am having issues.....
addTextBox.Width = 100%;

ListBoxDir.Items.Add(addTextBox);

Open in new window

0
I have an application that has been written for me and i have all the source code.  When i compile and run it i get the following error.  What can be causing this?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.ToolStripMenuItem' to type 'System.Windows.Forms.Control'.
   at Accusoft.FSInvoicesDemo.MDIParent2.localFolderToolStripMenuItem_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: …
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

hi,

I have gridview. chexbox is inside gridview. its giving an error when there is no data . Checkbox ix a bit field. How to resolve it.

  <asp:TemplateField HeaderText="Status"  HeaderStyle-HorizontalAlign="Left"   >
             <ItemTemplate>
                  <asp:CheckBox ID="lbIsActive" Enabled="false" runat="server"  Text="" Checked='<%# Eval("IsActive") == DBNull.Value ? false :  Eval("IsActive") %>' /> Is Active?
             </ItemTemplate>
             <EditItemTemplate>
                 <asp:CheckBox ID="rdIsActive" runat="server" Text="" Checked='<%# Eval("IsActive") == DBNull.Value ? false :  Eval("IsActive") %>'/> Is Active?
             </EditItemTemplate>
            <FooterTemplate>
                 <asp:CheckBox ID="inIsActive"  runat="server"  /> Is Active?
        
            </FooterTemplate>
         </asp:TemplateField>


c#
   protected void Page_Load(object sender, EventArgs e)
    { 
            if (!IsPostBack)
            {
                LoadAllApplications();
            }
}

   protected void LoadAllApplications()
    {
        try
        {
            AppAccessDataLayer obj = new AppAccessDataLayer();
            DataSet ds = obj.GetAllApplications();

            int count = ds.Tables[0].Rows.Count;
            if (ds.Tables[0].Rows.Count > 0)
            {
                gridView.DataSource = ds;
                gridView.DataBind();
            }
            else
            {
                

Open in new window

0
My WPF project has a MainWindow. The MainWindow has an "Open File" button on the toolbar. The "Open FIle" button when clicked sends an event to my VIewModel saying, "Hey, the user clicked the "Open File" button.

My ViewModel responds with "I need to display an Open File Dialog." It displays the Win32 Open File Dialog, and subscribes to that dialog's "OK" button click event.

User selects a file and clicks "OK".

My ViewModel responds to the "OK" click event, gets the file name from the Open File Dialog, and passes it to the Model, telling the Model, "Hey, the user wants to open this file."

Now I'm thinking of testability. I don't have Visual Studio Enterprise. I should be able to test my ViewModel without it actually displaying an Open File Dialog.

I had a situation where the ViewModel forgot to subscribe to the Open File Dialog's "OK" button click event. I now want to be able to test for this in my unit tests.

And I'm not sure how to do that.

(I'm also not sure if my View (MainWindow) should send a click event "User clicked the Open File icon", or if my View should send a Command "User wants to open a file." I'm thinking Command, since then the VIew can send the same Command when the user clicks the menu option for File Open. Otherwise I have my ViewModel handling the menu File Open click event separately. Are Commands preferable?)
0
Is there a way to force a file that is locked by another process to be moved/copied in C#?
0
my current database is MS-Access.

I used primary key in my table.

Also, First i am deleting record and then followed by inserting.

But, while inserting i am getting Error : Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

I am unable to find out the exact problem for this.

See my complete code.

string connectionstring1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbname + ";";
OleDbCommand command = new OleDbCommand();
OleDbTransaction transaction = null;
OleDbConnection cn1 = new OleDbConnection(connectionstring1);
cn1.Open();

// Start a local transaction
transaction = cn1.BeginTransaction();

// Assign transaction object for a pending local transaction.
command.Connection = cn1;
command.Transaction = transaction;

// Execute the commands.
string sqlTrunc = "DELETE FROM [" + tableName + "]";
OleDbCommand cmd = new OleDbCommand(sqlTrunc, cn);

cmd.ExecuteNonQuery();

transaction.Commit();
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbname + ";";
//using (OleDbConnection cn = new OleDbConnection(connectionstring))
using (OleDbConnection connection = new OleDbConnection(ConStr))
{
connection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand("SELECT * FROM [" + TABLENAME + "]", connection);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

adapter.Fill(newdt);

adapter.Update(newdt);

}

What is the …
0
I am trying to figure out how to create a folder select dialog.  Other postings I have seen suggest using System.Windows.Forms.FolderBrowserDialog.  I am trying to get away from Windows Forms, so implementing this would not make sense.

Is there a Folder select option in WPF?  If not, is there a third-party user control that you could recommend?  I also realize that I can make this myself using a user control in WPF however, I have no desire to “reinvent the wheel” if it already exists.

Any suggestions would be greatly appreciated.
2
I have the webmethod below and it works fine.
Now, I need to add database bind  because I have gridview inside of this page. In this case, what can i do?

 [WebMethod]
        public static string RemoveXMLData(int messageID)
        {
            string result = "";
            try
            {
                string templatePath = HttpContext.Current.Request.PhysicalApplicationPath + "UserMessages.xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(templatePath);
                try
                {
                    XmlNodeList nodeList = xmlDoc.SelectNodes("Users/User[MessageID = " + messageID + "]");

                    foreach (XmlNode xn in nodeList)
                    {
                        xn.ParentNode.RemoveChild(xn);
                    }                   
                    result = "Data deleted";                    
                }
                catch { result = "Some error in node deletion"; }
                finally
                {
                    xmlDoc.Save(templatePath);
                }
            }
            catch { result = "Eror in xml file loading"; }
            return result;
        }

     html = html + "<ul class='list-unstyled'>" +
                                          "<li class='left clearfix'>" +
                                          "<span class='chat-img1 pull-left' style='vertical-align: text-top;'>" +
                                          "<i class='fa 

Open in new window

0
I see alert message "Process cannot access the file because it is being used by another process".
when I click the button at third time. It seems reading is okay. but when i click the button to write something inside  to the xml.
it fails. how can i resolve this issue?

I know the  "Process cannot access the file because it is being used by another process". continue to happen the new message is sent.
sendMsg_Click(), but that does not mean the issues came from there.

And I check all controllers I used, and when the file is opened, it is closed immediately.

  protected void Page_Load(object sender, EventArgs e)
        {
            phoneNoList.DataSource = Utility.Controller.GetUniquePhoneNo(fromPhoneNo);
            phoneNoList.DataBind();
}

  protected void sendMsg_Click(object sender, EventArgs e)
        {
		 #region add a record to all message xml
                Domain.User u = new Domain.User();
                u.fullName = fullName.Text;
                u.from = "+1" + fromPhoneNo;
                u.to = "+1" + toPhoneNo.Text;
                u.body = body.Text;
                u.dateTimeSent = DateTime.Now.ToString();
                u.direction = "outbound-reply";
                string result = Utility.XML.Add(Utility.Controller.filePathUserMessagesAll, u);
                #endregion


}

  public static string Add(string inputFilePath,Domain.User u)
        {
            XDocument doc = XDocument.Load(inputFilePath);
            XElement user = 

Open in new window

0
I have created a controller for a KeyLog (users check in keys or check out keys) from a physical box.  I return a list of log entries to a free fqGrid control via json.  Below is my controller code:
var jsonData = new
            {
                rows = from logs in db.KeyLogs.Where(k => k.KeyId == id).ToList()
                       select new
                       {
                           id = logs.Id,
                           keyId = logs.KeyId,
                           removeDate = logs.KeyRemovedDate.HasValue ? logs.KeyRemovedDate.Value.ToString("MM/dd/yyyy") : "",
                           removeTime = logs.TimeOut.HasValue ? logs.TimeOut.Value.ToString("HH:mm:ss") : "",
                           returnDate = logs.KeyReturnedDate.HasValue ? logs.KeyReturnedDate.Value.ToString("MM/dd/yyyy") : "",
                           returnTime = logs.TimeIn.HasValue ? logs.TimeIn.Value.ToString("HH:mm:ss") : " ",
                           officer = logs.Officer
                       }
            };

Open in new window


The problem is that this code errors on the time vaues if one of them is null.  How can I get around this?  The date vaules are not a problem.
0
Along with this error there are more. I downloaded ups sample and it updated the files to viusal studio 2015. I am just trying the check address to see how it works before doing the shipping api. . Does anyone have a working example for anything from API ups that i could look at and try to figurage out how to get the samples to work. The project is in a zip file at http://rrrwebsite.com/
0
New feature and membership benefit!
LVL 9
New feature and membership benefit!

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

A  wonderful new day.

Am wriiting a window service application in C# and its supposed to call  a C programme from its OnStart() function.

My question is this :

(1 ) Can i develop a C WIN32API in Visual Studio 2017, if yes, how can i please.

(2) Starting from the OnStart() function  how  do i call the C application


Thank you
0
At work today where we support an SDK (.net one) someone asked if the C# SDK was a "signed" .NET SDK.

I wasn't 100% sure what they were talking about but I thought this was on the right track:
https://docs.microsoft.com/en-us/dotnet/framework/app-domains/how-to-sign-an-assembly-with-a-strong-name

Can someone explain to me what this is about and why they would need it? And also how difficult would it be to turn my unsigned SDK into a signed SDK?

Thank you
0
Hi experts,
I have a colum in a table, filled with numbers of eight digits.  
Let me give you an example of the column:
01482021
01466587
02447852
I read, one by one, each row of this column with a SQLDaraReader loop
while (reader.Read())
            {
                do the job 
            }

Open in new window

I need to split each line  in two numbers :
- one is composed of the first two digits. In the first line of the example table it will be "01"
- the other is composed with the remaining part : in the example it will be 482021 ; 466587 ; 447852
I want, after reading all the lines, to find the MAX (or highest) value of the set " 482021 ; 466587 ; 447852 ; etc.)
I've tried a lot of combinations of split and parse without success.
Can someone help me ?
0
Hi Experts,
I have an MVC.Net application that uses C#.Net code behind.
In my views I use a Kendo UI grid.  One of the columns in the grid is a link.

When the user clicks on the link it should open a .pdf file.  So we need to pass the file path and the file name.
How can I do this?

Thank you,
mrotor
0
I have an ASP.Net Core MVC application. I want to display the currently logged in user name. I asked a question earlier about something similar. Here I'm trying to display and grab the current username so that I can pass it to a function later to look up data in a database table with the username in a where clause. But I need to get the username. I've used Environment.UserName before, but it does not work in the .Net core app. I get an error:Environment does not contain a definition for UserName. Thanks.
0
Hello Experts,
I have hard time understanding the below code.  Please try to explain if possible.  I have a network user not able to sign into an application. Trying to see what could be wrong.  Thank you in advance.

DirectoryEntry de=new DirectoryEntry("GC://root.local");
DirectorySearcher ds= new DirectorySearcher(de,String.Format("(&(objectCategory=user)(objectClass=user)(samAccountName={0}))",strLogin));
SearchResultCollection results=ds.FindAll();

Thank you!
0

C#

92K

Solutions

25K

Contributors

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).