C#

94K

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

Hello Experts,

 I'm writing a C# program which insert huge data to Amazon Redshift table (one table).
I've wrote a loop over the  DataTable then insert a row by row to the table, This solution is OK but takesa lot of time if we talking about 1M rows.
The DataTable structure & the Redshift table are similar

Can you please help bulk insert the table to Redshift ?

Thanks,
 Jamil
0
Hi Experts,

I've a batch script for pinging multipal ip's, now i want convert this batch script to C# Windows Forms App (.NET Framework) & run ping with start button.

Please Suggest ?
COLO.txt
COLOPINGLOOP.txt
0
I have a small project to pick up SAML response inside of Page_load() in c#/aspx and I am new about this.
And I just need to pick up the value under
<saml2:AttributeStatement></>

and capture the value e.g. Pick Me Up. Do you know how to do that?

I just copy and paste the whole xml for you to review.


<saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
                 Destination="http://www.abc.com/Shibboleth.sso/SAML2/POST"
                 ID="_d73467246a0186aedf01809245da7aaa"
                 InResponseTo="44330487-3db3-48ec-8eed-9529a9b0e6ce"
                 IssueInstant="2019-09-17T17:49:25.168Z"
                 Version="2.0"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 >
  <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
                Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
                  >https://abc.xyz.safeabc.net/idp/shibboleth</saml2:Issuer>
  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <ds:Reference URI="#_d73467246a0186aedf01809245da7aaa">
        <ds:Transforms>
          <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            

Open in new window

0
I'm using a static class for my global variables. I wonder how is possible to raise an event for their value change?

For example "IsRunning" property changed from true to false i'd like to trigger some events on my gui.

Any help would be grateful.

namespace SCrEngine
{
    static class Globals
    {
        private static SpckCOMApp _appPre;
        public static SpckCOMApp AppPre
        {
            get
            {
                return _appPre;
            }
            set
            {
                _appPre = value;
            }
        }


        private static PostComApp _appPost;
        public static PostComApp AppPost
        {
            get
            {
                return _appPost;
            }
            set
            {
                _appPost = value;
            }
        }
        public static bool IsPreRunning
        {
            get { return AppPre != null; }
        }
        public static bool IsPostRunning
        {
            get { return AppPost != null; }
        }


    }
}

Open in new window

0
I'm trying to create a property like IsRunning for my COM object.

I'm defining a variable named myServer in different COM type class named SpckCOMApp.

If variable value turns to null, my IsRunning property should returns false otherwise it should be return true

SpckCOMApp myServer = null;

Open in new window


I don't know how to apply that? Am i need to create event?

If you have any ideas/solutions it'd be great for me.

Thanks.
0
Change code to support tasks.

Hi,

How can I change the WPF code below to support a non-blocking tasks.

So here is how it works now syncronisly

List<Event_Log> event_list = new List<Event_Log>();

for (int i=1;i<=10;i++)
{
    string description = "TEST" + i.ToString();
 
    event_list.AddRange(Get_Events(description));

}

--> Continue processing when all results are in from Loop.

I to change this to non-blocking Task

So each iteration of Get_Events is a task. While the code is working
it exits the method so the thread is non-blocking.

Then once all the tasks have finished doing there work
process the results

Psuedo code something like:

for (int i=1;i<=10;i++)
{
    string description = "TEST" + i.ToString();
 
    Start Task Get_Events(description)

}

if tasks-still running - exit method non-blocking

all tasks finished Task.WhenAll() - Guessing this is the correct way.

{
   Process results.

}

Here is my code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Security;

namespace WPF_EventTest1
{
    

Open in new window

0
in itextsharp c# how to populate fields in two or more PDF document
0
in c# n itextsharp, how to read all fields inside of pdf
0
do you know where I can get sample codes for google drive sheets for crud using c#?
0
I have been tasked with updating one of our sites with the ability to save Versions.  This would mean when a user Edits a Record, I would save the current Version, copy the Version with Edits and append a Version after the ID (or something similiar).  They need to be able to compare versions of a record so I have to be able to show it to the user upon request.

I"m looking for any tutorials or help on the best approach to this. Thanks so much!
0
I've COM-interface in my application and Reference properties like below;

Name: Interop.simpackcomslvLib
Embed Interop Types: True
File Type: ActiveX
Isolated: False

I'm creating a new instance of it with below code;

myAPP = new simpackcomslvLib.SpckCOMApp();

Open in new window


and this is how i'm trying to disconnect from com interface;

Marshal.ReleaseComObject(myAPP);
myAPP = null;
return;

Open in new window


I don't know it's full true and clear way of it or i need to do additional things.

The other things when i'm connecting a COM interface it's instantly creating process and i can see it on Task Manager>Processes but when i'm releasing it, the processes stays there almost 1-2 minutes then disappears from Task Manager>Processes.

Is there anyway to release it instantly ? Or is there a way to check is it fully released because i don't want to create new instance once it's fully released.
0
Hi All,

I want to send message to WA from desktop application using https://web.whatsapp.com/

Please see below code.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MaiWA
{
    public class CWhatsapp
    {
        private const string QR_CODE_XPATH = "//img[@alt='Scan me!']";
        private const string SEARCH_INPUT_XPATH = "//input[@title='Search or start new chat']";
        private const string CHAT_INPUT_XPATH = "//div[@class='_2S1VP copyable-text selectable-text']";
        //private static int TUNDA = 2000;
        private static IWebDriver _driver = null;

        public void StartWhatApp()
        {
            _driver = new ChromeDriver(new ChromeOptions { LeaveBrowserRunning = false });
            _driver.Url = "https://web.whatsapp.com";

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
            _driver.Navigate();
        }

        public bool OnLoginPage()
        {
            try
            {
                if (_driver.FindElement(By.XPath(QR_CODE_XPATH)) != null)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
            return false;
        }

        public void StopWhatApp()
        {
            _driver.Quit();
            _driver.Dispose();
        }

        public bool KirimText(string 

Open in new window

0
I'm a big fan of ClosedXML and looking for the same type library which is using OpenXML SDK and free without any limitation.

I searched on Google and the results saying there's no free but i'd like to ask EE users.

Any suggestion/help would be grateful.

Thanks.
0
I've very simple code which assigns a COM type object to global variable named Global.MDL with below code.

        private bool OpenSimpackModel(String filename)
        {
            try
            {
                Globals.MDL = Globals.APP.Spck.openModel(filename);
                if (Globals.MDL != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
                throw;
            }

        }

Open in new window


But while it's trying to assigns it tookes some time and locks my gui controls, at least i'd like to show loading bar until this process completed otherwise user don't know what is causing that.

How is it possible to show loading bar when application start to call  below function.

             Globals.MDL = Globals.APP.Spck.openModel(filename);

Open in new window


Any help would be grateful.

Thank you.
0
I have code like below to use COM, the COM client has to start a COM server with SpckCOMApp class.

To apply that i have a variable named Globals.APP with type SpckCOMApp;

I'm creating a new instance of that with below code.


		private bool ConnectComApp()
        {
            try
            {
                Globals.APP = new simpackcomslvLib.SpckCOMApp();
                if (Globals.APP != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }

Open in new window


and to apply it on tool startup i'm calling it on Loaded event.

      private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ConnectComApp();
        }

Open in new window


But the problem is when i'm running tool it just appears with blank gui after new instance created the all gui elements appears.

Does anyone know the correct way of creating COM instance and calling it in correct event maybe i have to try different event on startup.

Thank you.
0
We have a console app which pulls data from rabbitMQ and then pushes via websocket (signalR) to web app

However we have noticed that when there is a small outage, there are many messages in the queue and it takes a while to catch up
What we need to do is process from Last message in queue backwards, then we could check the timestamp and see if its older than what was already sent and discard old data.
I read some old articles online that said LIFO is not supported by rabbitMQ

If not are there other queues/tech to look at?
Alternatively we could get all messages into c# and then flip the order, but as many messages are coming in at same time we'd opt for a more simple solution first if there is one
0
I have a Windows Forms application that is using a custom drawn window. On this form I have controls that simulate a normal Windows header and footer.

This little trick works great for passing mouse click events through to the underlying control
		private const int WM_NCHITTEST = 0x0084;
		private const int HTTRANSPARENT = (-1);

		protected override void WndProc(ref Message m)
		{
			if (m.Msg == WM_NCHITTEST && !this.DesignMode)
			{
				m.Result = (IntPtr)HTTRANSPARENT;
			}
			else
			{
				base.WndProc(ref m);
			}
		}

Open in new window

However, I also need the underlying control to be able to see mouse move events as well. Right now that's not working. Can anyone tell me what I need to do in addition to the above to pass mouse move events through to the form?
0
Hello,
I am working on a VS2008 project which uses crystal reports.
All the crystal reports appear with VS2017 icon and when i click on it , it would not open. Instead it gives the message
"Please wait while windows configures Crystal Reports Basic for VS 2008."
What should be done to fix this issue?
crystal report  .rpt file


Thanks in Advance
0
Hi I am using ASP.Net MVC with C# and I have a webpage with some buttons. Is there a way I can simulate clicking one of the buttons from code behind in the controller? Thank you.
0
I have this string in json {"columnC":"1","columnA":"2","columnB":"2"}
How can I use for loop to generate  like

ColumnC: 1
ColumnA: 2
ColumnB: 2

Thanks
0
Hello all!  I am hoping this issue is an obvious one to someone 😊  I have a Windows Forms application that does some independent processes on separate sub-forms.  It has a MainForm that opens first and then it opens the sub-forms based on an “is active” database value for each sub-form.  This process runs as expected often for many hours without any issues… opening and closing when necessary.  The issue that I am having trouble figuring out is one where the application just freezes and has to be manually closed and restarted which of course while it isn’t running stops processing altogether.  

There are always 2 errors in the Windows Application error log.  First is a “.Net Runtime” and the second is a “Application Error”.  There is a third Information entry that appears to be logged when the application is restarted but not 100% certain if it is present before it is restarted.  

The MainForm is opening the different sub-forms in a new thread using different versions of this:

try
{
Thread CS = new Thread(new ThreadStart(CS_Start));
CS.SetApartmentState(ApartmentState.STA);
CS.Start();
}
catch { }

Open in new window


And this is the code it is called in the new thread which is opens one of the sub-forms…

private void CS_Start ()
        {
            try
            {
                using (CS_Searches CS_SearchForm = new CS_Searches())
                {
                    if (!CS_SearchForm.Visible)
                        CS_SearchForm.ShowDialog();
                }
            }
            catch { }
        }

Open in new window

0
I have Json & MVC / c# question below:

the var json = JSON.stringify(data); return json format
like {"column":"1","columnA":"2"}

My question is inside of the C# mvc ReceiveJson: How to extract the value like

column = 1
columnA = 2

and i want to be like insert table column, columnA values (1,2)

And {"column":"1","columnA":"2"} is it a json format?

*** formdiv *** inside of it, it just a combination of some <input id='column'> or <select id='columnA'>
function Submit(domain) {
    var x = $('#formdiv *').serializeArray();
    var data = {};
    $.each(x, function (i, field) {
        data[field.name] = field.value;
    });
    var json = JSON.stringify(data);
    alert(json);
    $.ajax({
        url: domain + "/Api/ReceiveJson",
        type: "POST",
        data: {
            'message': json
        },
        dataType: 'json',
        success: function (data) {
            alert(data.BondCode);
        },
        error: function (msg) { alert(msg); }
    });
    return false;
}

[HttpPost]
        public JsonResult ReceiveJson(List<string> message)
        {             
            var jsonResult = Json(message);
            domainCompanyBondType.BondCode = "1";
            return Json(domainCompanyBondType, JsonRequestBehavior.AllowGet);
        }

Open in new window

0
I am trying to get a old C# service back up and running. In VS2019 I can build the service successfully and view it in the browser. However when I move it to IIS 8.5 I am no longer able to browse the service. Instead I get an HTTP Error 404. IIS-Service-error.docx

I have detailed the steps I have taken in the attached word document. If someone could help me out I'd appreciate it.
0
Database:  SQL
Environment: Visual Studio and C#

Hello Experts,
I am trying to read a table and write the data in 3 tables.  What is the best read/write and loop I should use.

Thank you in advance!
0
I am using Windows Forms and a RichTextBox in c# (Studio 2017) to create a basic editor and now want to add a table. I can do this though the method is very cumbersom, however cannot find an rtf specification, all links I follow are broken. So, two questions:

1. Can anyone point me to an rtf specification?
2. Is there a better way (ie xml?) to do this sort of thing now.
0

C#

94K

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