|
Yeah, I forgot about .NET Standard Libraries.
|
|
|
|
|
The NuGet package you have referenced depends on other NuGet packages:
NuGet Gallery | System.Text.Json 5.0.2[^]
Specifically, for .NET Framework 4.x, it depends on:
- Microsoft.Bcl.AsyncInterfaces (>= 5.0.0)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.4)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 5.0.0)
- System.Text.Encodings.Web (>= 5.0.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.ValueTuple (>= 4.5.0)
You will need to make sure all of those packages, and all of their dependencies (and their dependencies' dependencies etc.), are present in the same folder as your dll.
Alternatively, change your code to use Json.NET , which has no dependencies:
NuGet Gallery | Newtonsoft.Json 13.0.1[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I was trying to login to a site programmatically. i am loading site into web browser control. i tried this code but it did not worked. https://auth.accounts.dowjones.com/login
Sorry could not share actual credentials.
HtmlElement username = null;
HtmlElement password = null;
HtmlElement submit = null;
foreach (HtmlElement divcontainer in webBrowser1.Document.GetElementsByTagName("div"))
{
if (divcontainer.GetAttribute("className") == "text-input")
{
foreach (HtmlElement child in divcontainer.Children)
{
if (divcontainer.GetAttribute("className") == "js-email-input")
{
username = divcontainer;
}
if (divcontainer.GetAttribute("className") == "password js-password-input")
{
password = divcontainer;
}
}
}
if (divcontainer.GetAttribute("className") == "sign-in")
{
foreach (HtmlElement child in divcontainer.Children)
{
if (divcontainer.GetAttribute("className") == "solid-button basic-login-submit")
{
submit = divcontainer;
}
}
}
}
if (username != null && password != null && submit != null)
{
username.SetAttribute("value", "test@gmail.com");
password.SetAttribute("value", "test11");
submit.InvokeMember("click");
}
please some one guide me what to change in my code to automate login.
Thanks
|
|
|
|
|
This seems logical. What's not working?
"Did not work" does not help. Did it click the button? Did the text appear in the controls? Did it start playing Pacman?
|
|
|
|
|
the code i have mention in my post which is not filling textbox and not clicking button. so help me where i made the mistake?
|
|
|
|
|
Either you didn't wait for the page to finish loading, or the elements in the page don't match the elements you're looking for.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Issue sorted. i have done the job this way and it worked.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete && IsRedirect)
{
System.Threading.Thread.Sleep(5000);
timer1.Enabled = true;
}
else if (webBrowser1.ReadyState == WebBrowserReadyState.Complete && IsloginPage)
{
mshtml.IHTMLDocument2 htmlDocument = (mshtml.IHTMLDocument2) webBrowser1.Document.DomDocument;
mshtml.IHTMLElementCollection objforms = htmlDocument.forms;
foreach (mshtml.HTMLFormElementClass form in objforms)
{
if (form.className == "form")
{
IHTMLElementCollection inputElements = form.getElementsByTagName("INPUT");
foreach (HTMLInputElementClass inputElement in inputElements)
{
if ((inputElement.type.Trim().ToLower() == "email") && (inputElement.name.Trim() == "email"))
{
inputElement.value = "Test_UID@gmail.com";
}
else if ((inputElement.type.Trim().ToLower() == "password") && (inputElement.name.Trim() == "password"))
{
inputElement.value = "Test_PWD";
}
}
IHTMLElementCollection inputElements1 = form.getElementsByTagName("BUTTON");
foreach (HTMLButtonElementClass inputElement in inputElements1)
{
if ((inputElement.innerText.ToLower() == "sign in") && (inputElement.type.Trim().ToLower() == "submit")
&& (inputElement.tagName.Trim().ToLower() == "button"))
{
inputElement.click();
break;
}
}
}
}
}
}
Thanks
|
|
|
|
|
code curve in c#.image processing
|
|
|
|
|
Was that supposed to be a question?
|
|
|
|
|
Do you mean the Graphics.DrawArc Method (System.Drawing) | Microsoft Docs[^]?
If not, you are going to have to explain in a lot more details as we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hey,
I'm new to C# and coding in general. I've done some reading and online "hands-on" tutorials but I'm truly stuck here. Can someone please help me out and review the code I have written? I'm willing to put the time in to learn, I just don't know where to go from here.
I'm having a problem with my switch statement that involves different levels of commission rates, as well as getting the calculation to work. Also, on my last line it is giving me an error -- saying that "dblCalculateCommission" is an unassigned variable. I haven't had this problem on similar exercises. Appreciate any help, ready to pull my hair out!
private void btnCalculateCommission_Click(object sender, EventArgs e)
{
// declare variables to be used in the calculation
double dblSalesPersonLevel;
double dblAmountSold;
double dblCalculateCommission;
// convert the values in the text boxes to numeric and place into variables
dblSalesPersonLevel = Convert.ToDouble(txtSalesPersonLevel.Text);
dblAmountSold = Convert.ToDouble(txtAmountSold.Text);
// check the sales level is between 1 and 4, if it is outside of these parameters display an error message
if (dblSalesPersonLevel < 1)
{
MessageBox.Show("Sales level cannot be less than 1", "Input Error");
txtSalesPersonLevel.SelectAll();
txtSalesPersonLevel.Select();
}
else if (dblSalesPersonLevel > 4)
{
MessageBox.Show("Sales level cannot be greater that 4", "Input Error");
txtSalesPersonLevel.SelectAll();
txtSalesPersonLevel.Select();
}
// Calculate commissions based on sales person level
{
string strSalesPersonLevel;
strSalesPersonLevel = txtSalesPersonLevel.Text;
switch (strSalesPersonLevel)
{
case "1":
{
dblCalculateCommission = 500 + (dblAmountSold * 0.02);
break;
}
case "2":
{
dblCalculateCommission = 750 + (dblAmountSold * 0.03);
break;
}
case "3":
{
dblCalculateCommission = 1000 + (dblAmountSold * 0.04);
break;
}
case "4":
{
dblCalculateCommission = 1250 + (dblAmountSold * 0.05);
break;
}
}
// Convert commission into a string and place into a label with currency
//formatting
lblCalculateCommission.Text = dblCalculateCommission.ToString("C2");
|
|
|
|
|
The code is incomplete and badly formatted so it's going to be a bit of guess work.
The first thing that sticks out to me is why is there a set of curly braces that don't belong?
{ <--- This shouldn't be here
string strSalesPersonLevel;
strSalesPersonLevel = txtSalesPersonLevel.Text;
...
case "4":
{
dblCalculateCommission = 1250 + (dblAmountSold * 0.05);
break;
}
} <--- This shouldn't be here
lblCalculateCommission.Text = dblCalculateCommission.ToString("C2");
|
|
|
|
|
Try something like this:
private void btnCalculateCommission_Click(object sender, EventArgs e)
{
if (!int.TryParse(txtSalesPersonLevel.Text, out var salesPersonLevel) || salesPersonLevel < 1 || salesPersonLevel > 4)
{
MessageBox.Show("Invalid sales person level.", "Input Error");
txtSalesPersonLevel.SelectAll();
txtSalesPersonLevel.Select();
return;
}
if (!double.TryParse(txtAmountSold.Text, out var amountSold))
{
MessageBox.Show("Invalid amount sold.", "Input Error");
txtAmountSold.SelectAll();
txtAmountSold.Select();
return;
}
double calculatedCommission;
switch (salesPersonLevel)
{
case 1:
{
calculatedCommission = 500 + (amountSold * 0.02);
break;
}
case 2:
{
calculatedCommission = 750 + (amountSold * 0.03);
break;
}
case 3:
{
calculatedCommission = 1000 + (amountSold * 0.04);
break;
}
case 4:
{
calculatedCommission = 1250 + (amountSold * 0.05);
break;
}
default:
{
calculatedCommission = 0;
break;
}
}
lblCalculateCommission.Text = calculatedCommission.ToString("C2");
} If you're using a recent compiler and C# 8 or later, you can use a switch expression instead:
double calculatedCommission = salesPersonLevel switch
{
1 => 500 + (amountSold * 0.02),
2 => 750 + (amountSold * 0.03),
3 => 1000 + (amountSold * 0.04),
4 => 1250 + (amountSold * 0.05),
_ => 0
}; switch expression - C# reference | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you both for the reply -- appreciate the help!
|
|
|
|
|
I have a problem with identifying printers,
the problem is how to unequivocally identify the printer to clearly state that, for example, after switching the printer to another computer, be sure that the printer has been switched and not the same second added.
It is possible to read the identifier from the PNPDeviceID field of the device (some of this is our identifier, I think so) listing the devices connected to the USB. One of them will be "Universal USB printer", i.e. our printer, but I have not found any information on how to pair the printer installed with the device connected to the USB.
Or some other better way to get S / N from a connected printer and assign it to a specific printer downloaded using e.g. System.Drawing.Printing.PrinterSettings.InstalledPrinters
Thx Piter
|
|
|
|
|
The only thing I found that came close to a S/N was the "PortName" (Brother printers in my case).
string query = "SELECT * FROM Win32_Printer";
ManagementObjectSearcher searcher = new ManagementObjectSearcher( query );
var services = searcher.Get();
foreach ( ManagementObject service in services ) {
var properties = service.Properties;
foreach ( PropertyData p in properties ) {
if ( p.Value == null ) { continue; }
Console.WriteLine( $"{p.Name}: [{p.Value}]" );
}
}
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
SzakiII wrote: I have a problem with identifying printers First let me say that I am not a C# developer. All I can offer is the correct nomenclature and some guidance on how the operating system works and how I would obtain this using the native Windows API. So if you had 10 identical BrandX printers installed the Microsoft Windows operating system differentiates these by appending a unique device instance id[^] to the hardware id string.
As a native programmer I would call GetPrinterDriver function[^] with DRIVER_INFO_6[^] and obtain the hardware ID. Then I would tokenize the string and extract the unique device instance id[^]. You could also call the EnumPrinterDrivers function[^] to get DRIVER_INFO_6[^] for all of the installed printers. This would work for both local and network shared printers.
Maybe another codeproject member knows of a C# managed way to get to the device instance id. The unique identifier is at the end of the string:
PCI\VEN_1000&DEV_0001&SUBSYS_00000000&REV_02\1&08
Best Wishes,
-David Delaune
|
|
|
|
|
A "Hardware Id" (or "instance" id) is not same as a Serial Number.
Quote: A hardware ID is a vendor-defined identification string that Windows uses to match a device to an INF file. In most cases, a device has more than one hardware ID associated with it. Typically, a list of hardware IDs is sorted from most to least suitable for a device.
Hardware ID - Windows drivers | Microsoft Docs
If you look at the (contents of) "PortName", you will see the days of "LPT1, etc." are long gone (i.e. before serial numbers)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 15-Jun-21 19:21pm.
|
|
|
|
|
Hi Gerry,
Gerry Schmitz wrote: A "Hardware Id" (or "instance" id) is not same as a Serial Number. Some humble comments:
1.) Actually that is not entirely correct. The hardware ID is handled by the driver IRP_MN_QUERY_ID[^] request handler and might contain a serial number if Parameters.QueryId.IdType is set to BusQueryDeviceSerialNumber and if the device manufacturer/vendor has supplied it.
2.) A serial number is optional and might not be present. It is completely optional and the device manufacturer is not required to set this information.
3.) You can ask the device if it is capable of giving a serial number by sending a IRP_MN_QUERY_CAPABILITIES[^] request. If the device can supply a serial number then the UniqueID field in the DEVICE_CAPABILITIES structure[^] will be set to TRUE.
4.) The Windows operating system internally is using the device instance ID[^] to uniquely identify devices.
5.) The device instance ID is appended to the tail end of the hardware ID you mentined.
Best Wishes,
-David Delaune
P.S.
If the author of the post wants to write code that would only work with USB printers then he might be able to get something from the USB device descriptor[^]. The USB_DEVICE_DESCRIPTOR structure[^] which contains the same unique identifier. I believe it is also optional and the manufacturer is not required to set this information.
Best Wishes,
-David Delaune
|
|
|
|
|
i have string in Arabic language but it's appear like that
Ï Ì Í Î å Ú Û Ý Þ Ë Õ Ö Ø ã ä Ê Ç Ã á áÃ
Basically I need to convert My source string to Arabic and I do it using following code:
i try
string responseXML = Encoding.UTF8.GetString(Encoding.Default.GetBytes(responseXML));
result
Ï Ì Í Î å Ú Û Ý Þ Ë Õ Ö Ø ã ä Ê Ç Ã á áÃ
but the right result is
string"د ج ح خ ه ع غ ف ق ث ص ض ط م ن ت ا أ ل لأ ب ي س ش ظ ز و ة ى لا ر ؤ ء ئ ذ"
What I'm doing wrong here?
|
|
|
|
|
You're probably using the wrong encoding.
What encoding does the HTTP response declare?
Content-Encoding - HTTP | MDN[^]
What encoding does the XML document declare (if any)?
XML Declaration - Wikipedia[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i get data from QuickBooks like this
*أاإ ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ
it retrain
the encoding of the xml response declare is ISO-8859-1 (ISO Latin 1)
like this
Ï Ì Í Î å Ú Û Ý Þ Ë Õ Ö Ø ã ä Ê Ç Ã á áÃ
i didn't find away to convert it to Arabic direct so i convert it to html encode
like this
Ï Ì Í Î å Ú Û Ý Þ Ë Õ Ö Ø ã ä Ê Ç Ã á áÃ
now i want to convert html encode to Arabic i don't know how can help me thanks
|
|
|
|
|
If the data is encoded using ISO-8859-1, then you can't use UTF8 to decode it.
You need to specify the correct encoding:
Encoding iso = Encoding.GetEncoding("ISO-8859-1");
The question remains, since you already have a string, why are you decoding it to bytes simply to encode it back to a string?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Just print / display responseXML before tinkering with it. Your "result" is single byte characters where the "right result" (and input apparently) happens to be "double-byte" characters.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I tried this code:
<pre lang="C#"> if (DGVName.Rows.Count >= 1)
{
foreach (DataGridViewRow row in DGVName.Rows)
{
row.HeaderCell.Value = (row.Index + 1).ToString();
}
}
But it gives the following runtime error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
|
|
|
|