|
Sajo Nezic wrote: It often throws out various errors to me
You need to show the code and explain what are the errors, otherwise we can't help you to fix your code.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
There is a lengthy discussion (with code examples) of generating random decimal numbers in C# here: [^].
imho, very few apps need greater random number "integrity" than that provided by the Framework (see OriginalGriff's solution, here), or, by using the other native crypto facilities: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
BillWoodruff wrote: There is a lengthy discussion (with code examples) of generating random decimal numbers in C# here: [^].
and a much simpler one at xkcd: Random Number[^] (read the tooltip text)
|
|
|
|
|
Hello
I have a problem statement for which looking for a solution.
Requirement:
1. I have around 1000 files and all are in different folders e.g
2020-08-11->
Folder 1 -> file 1
folder 2 -> file 2
2. Wanted to write a program which will extract lines from these files and create one output file
3. Input Lines to read came from Database table e.g
one column in table which stores the input for the program.
Any suggestion or reference is appreciated. Not a good at C# programming
|
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
All we have so far is a "wish list"!
"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!
|
|
|
|
|
lalgourav wrote: Any suggestion or reference is appreciated. Not a good at C# programming This is a C# programming forum. You can ask for help, but not solutions.
lalgourav wrote: I have around 1000 files and all are in different folders If this asked during an interview I just leave without a word; 10, 1000, or 20000 items is the same loop.
lalgourav wrote: Any suggestion or reference is appreciated. Hire someone. You have 32 teeth, 16 bottom, 16 top. I know the numbers, the locations, the theory, but still you wouldn't want me as a dentist. Not even after a two-month course.
You need a programmer? Hire one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi everyone!
Does anyone have a sniblet to be able to detect if the device is enabled or disabled in device manager. I've done a bit a searching and couldn't find anything of use when attempting to get a status of a device.
What I have so far, it appears the value I am obtaining by marshaling my Data stays the same regardless of its status so my API call is incorrect or the way I am marshaling out and I was hoping one of you may have a sniblet that actually works.
Below are two failed attempts at getting the device status :\
Thank you!!
public static bool GetDeviceState(Func<string, bool> filter)
{
var dpk = new DEVPROPKEY();
dpk.fmtid = new Guid("60b193cb-5276-4d0f-96fc-f173abad3ec6");
dpk.pid = 2;
var displayDevClass = new Guid("{ca3e7ab9-b4c3-4ae6-8251-579ef933890f}".ToString());
var hDevInfo = SetupDiGetClassDevs(ref displayDevClass, null, IntPtr.Zero, DiGetClassFlags.DIGCF_PRESENT | DiGetClassFlags.DIGCF_DEVICEINTERFACE);
if (hDevInfo != INVALID_HANDLE_VALUE)
{
uint i = 0;
while (true)
{
var did = new SP_DEVINFO_DATA();
did.cbSize = (uint)Marshal.SizeOf(did);
if (!SetupDiEnumDeviceInfo(hDevInfo, i, out did)) break;
uint required = 0;
DEVPROPTYPE dpt = 0;
var temp = new byte[0];
SetupDiGetDeviceProperty(hDevInfo, ref did, ref dpk, ref dpt, temp, 0, ref required);
if (required > 0)
{
var data = new byte[required];
if (SetupDiGetDeviceProperty(hDevInfo, ref did, ref dpk, ref dpt, data, required, ref required))
{
Debug.WriteLine(BitConverter.ToString(data));
}
}
}
}
IntPtr info = IntPtr.Zero;
Guid NullGuid = Guid.Empty;
try
{
info = SetupDiGetClassDevsW(ref NullGuid, null, IntPtr.Zero, DIGCF_ALLCLASSES);
CheckError("SetupDiGetClassDevs");
SP_DEVINFO_DATA devdata = new SP_DEVINFO_DATA();
devdata.cbSize = (UInt32)Marshal.SizeOf(devdata);
for (uint i = 0; ; i++)
{
SetupDiEnumDeviceInfo(info, i, out devdata);
if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS)
CheckError("No device found matching filter.", 0xcffff);
CheckError("SetupDiEnumDeviceInfo");
string devicepath = GetStringPropertyForDevice(info, devdata, 1);
uint CM_DEVCAP_HARDWAREDISABLED = 0x100;
uint proptype, outsize;
IntPtr buffer = IntPtr.Zero;
SetupDiGetDeviceRegistryPropertyW(info, ref devdata, (uint)SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES, out proptype, IntPtr.Zero, 0, out outsize);
uint buflen = outsize;
buffer = Marshal.AllocHGlobal((int)buflen);
outsize = 0;
SetupDiGetDeviceRegistryPropertyW(info, ref devdata, (uint)SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES, out proptype, buffer, buflen, out outsize);
byte[] lbuffer = new byte[outsize];
Marshal.Copy(buffer, lbuffer, 0, (int)outsize);
int errcode = Marshal.GetLastWin32Error();
if (errcode == ERROR_INVALID_DATA) return false;
CheckError("SetupDiGetDeviceProperty", errcode);
uint capabilities = BitConverter.ToUInt32(lbuffer, 0);
capabilities = getDWORDProp(info, devdata, SetupDiGetDeviceRegistryPropertyEnum.SPDRP_CAPABILITIES);
uint bitwise = capabilities & CM_DEVCAP_HARDWAREDISABLED;
bool isHardwareDisabled = bitwise > 0;
Debug.WriteLine(devicepath);
Debug.WriteLine(" - HARDWAREDISABLED: " + isHardwareDisabled.ToString().Trim() + " Compat: " + capabilities.ToString());
if (devicepath != null && filter(devicepath)) break;
}
}
finally
{
if (info != IntPtr.Zero)
SetupDiDestroyDeviceInfoList(info);
}
return true;
}
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetupDiGetDeviceRegistryProperty(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA deviceInfoData, uint property, out UInt32 propertyRegDataType, byte[] propertyBuffer, uint propertyBufferSize, out UInt32 requiredSize);
public enum RegType : uint
{
REG_BINARY = 3,
REG_DWORD = 4,
REG_EXPAND_SZ = 2,
REG_MULTI_SZ = 7,
REG_SZ = 1
}
const int BUFFER_SIZE = 1024;
static string getStringProp(IntPtr h, SP_DEVINFO_DATA da, SetupDiGetDeviceRegistryPropertyEnum prop)
{
UInt32 requiredSize;
UInt32 regType;
byte[] ptrBuf = new byte[BUFFER_SIZE];
if (!SetupDiGetDeviceRegistryProperty(h, ref da, (uint)prop, out regType, ptrBuf, BUFFER_SIZE, out requiredSize))
throw new InvalidOperationException("Error getting string property");
if (regType != (uint)RegType.REG_SZ || (requiredSize & 1) != 0)
throw new InvalidOperationException("Property is not a REG_SZ");
if (requiredSize == 0)
return "";
return Encoding.Unicode.GetString(ptrBuf, 0, (int)requiredSize - 2);
}
static uint getDWORDProp(IntPtr h, SP_DEVINFO_DATA da, SetupDiGetDeviceRegistryPropertyEnum prop)
{
UInt32 requiredSize;
UInt32 regType;
byte[] ptrBuf = new byte[4];
if (!SetupDiGetDeviceRegistryProperty(h, ref da, (uint)prop, out regType, ptrBuf, 4, out requiredSize))
throw new InvalidOperationException("Error getting DWORD property");
if (regType != (uint)RegType.REG_DWORD || requiredSize != 4)
throw new InvalidOperationException("Property is not a REG_DWORD");
return BitConverter.ToUInt32(ptrBuf, 0);
}
|
|
|
|
|
Hi, I'm not familiar with most of the functions you're using, but maybe this helps:
I once was interested in the enable/disable status of my Ethernet connection, as set in the Control Panel Network Connections (which might be different from the choice offered in Device Manager).
I used WMI (class Win32_NetworkAdapter), and checked property NetConnectionStatus which was zero for disabled and non-zero (7 IIRC) for enabled.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Here is fresh code that works for me:
using System;
using System.Management;
namespace LP_Core {
public class LP_Ethernet {
public static string GetState() {
string query = "SELECT NetConnectionStatus FROM Win32_NetworkAdapter "+
"WHERE NetConnectionID='Ethernet'";
ManagementObjectSearcher ethernets = new ManagementObjectSearcher(query);
foreach (ManagementObject ethernet in ethernets.Get()) {
switch (Convert.ToInt32(ethernet["NetConnectionStatus"])) {
case 0:
return "disabled";
case 7:
return "enabled but disconnected";
case 2:
return "enabled and connected";
default:
return "unknown";
}
}
return "absent";
}
}
}
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
modified 10-Aug-20 21:38pm.
|
|
|
|
|
Luc is being modest. If he says he got a better idea, you better follow it.
Not every device is complete in terms of device-drivers. I have a mountain of webcams that don't work under Linux to prove so.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Bonjour,
Je voulais déployer mon web service en IIS.
Ce web service crée en C# permettant de connecter à une base oracle 11g.
J'ai utilisé comme connecteur Oracle Data Access.
Le web service fonctionne localement mais après déploiement j'ai le message suivant :
Oracle.DataAccess.Client.OracleConnection --> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client à Oracle.DataAccess.Client.OracleInit.Initialize()
Le connecteur Oracle Data Access est en 32 bits alors j'ai activé les applications 32bits en IIS mais le même problème.
Merci.
Google translate: Hello,
I wanted to deploy my web service in IIS.
This web service created in C # allowing to connect to an Oracle 11g database.
I used as Oracle Data Access connector.
The web service works locally but after deployment I have the following message:
Oracle.DataAccess.Client.OracleConnection -> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client à Oracle.DataAccess.Client.OracleInit.Initialize ()
The Oracle Data Access connector is 32-bit so I enabled 32-bit applications in IIS but the same problem.
Thank you.
|
|
|
|
|
Read the error message:
The provider is not compatible with the version of Oracle client
It means that the engine and client versions are not compatible: you are trying to access a newer DB with an older client (or possibly vice versa but it's unlikely).
Think about it: if your code is written for V1.0 of a file format, and you try to work with a V5.6 file you would corrupt the file or discard data.
That's what the error is saying: "it's too new for me, I don't understand the differences, so I'm not going to risk your data"
Google translate: Lisez le message d'erreur:
Le fournisseur n'est pas compatible avec la version du client Oracle
Cela signifie que les versions du moteur et du client ne sont pas compatibles: vous essayez d'accéder à une base de données plus récente avec un client plus ancien (ou peut-être l'inverse mais c'est peu probable).
Pensez-y: si votre code est écrit pour la V1.0 d'un format de fichier et que vous essayez de travailler avec un fichier V5.6, vous corrompriez le fichier ou supprimeriez des données.
C'est ce que dit l'erreur: "c'est trop nouveau pour moi, je ne comprends pas les différences, donc je ne vais pas risquer vos données"
In future, please use Google or Bing to translate French - this is an English language site!
Google translate: À l'avenir, veuillez utiliser Google ou Bing pour traduire le français - c'est un site en anglais!
"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!
|
|
|
|
|
Bonjour,
Merci pour votre message.
Voici la version de base :
Oracle Database 11g Entreprise Edition Relase 11.2.0.4.0 - 46bit Production
Voici la version de driver ODAC112040Xcopy_32bit
avec l'ensemble de .dll :
oci.dll
ociw32.dll
Oracle.DataAccess.dll
oramts.dll
oramts11.dll
oramtsus.dll
orannzsbb11.dll
oraocci11.dll
oraociei11.dll
oraOps11w.dll
orasql11.dll
Le projet web service fonctionne tout seul et aussi lorsque j'ai inclu dans un autre projet.
Maintenant, je voulais déployer le web service pour que ceux qui veulent les utiliser alors ils peuvent le référencer à travers l'URL de ce web service.
Mais le même message d'erreur !!!
|
|
|
|
|
Once again: This is an English-lanugage site. Please post in English.
Ceci est un site en anglais. Veuillez poster en anglais.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
Thank you for your message.
Here is the basic version:
Oracle Database 11g Enterprise Edition Relase 11.2.0.4.0 - 64it Production
Here is the driver version ODAC112040Xcopy_32bit
with the set of .dll:
oci.dll
ociw32.dll
Oracle.DataAccess.dll
oramts.dll
oramts11.dll
oramtsus.dll
orannzsbb11.dll
oraocci11.dll
oraociei11.dll
oraOps11w.dll
orasql11.dll
The web service project works by itself and also when I have included it in another project.
Now, I wanted to deploy the web service so that those who want to use it so they can reference it through the URL of this web service.
But the same error message !!!
|
|
|
|
|
It looks like you are trying to mix 32-bit and 64-bit, which will not work.
|
|
|
|
|
So, you found an English site and decided to post in French?
Je voulais un chien de bbq. Avec une croissont.
You installed the wrong drivers. The error hints at it. Make sure the croissant warm
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Mon aéroglisseur est plein d'anguilles.
"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!
|
|
|
|
|
Wenn ist das Nunstück git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Romanes eunt domus?
"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!
|
|
|
|
|
Now write the correct phrase, Romani ite domum, 100 times,
Wrong is evil and must be defeated. - Jeff Ello
Never stop dreaming - Freddie Kruger
|
|
|
|
|
Good day.I have a VS2017 C# solution (A) with 3 projects under this solution and the whole solution is in Git repository.
Now, I just created a small Windows form solution C# (B) with single project. How can I add this new solution(B) to the existing solution(A) so that at the end I can push the exisitng git repository(A) along with the new solution as part of it. I tried this way: Added solution folder of B to the solution folder of A. Now what? I can open up Team explorer in A or B. How can I achieve this in VS or in Git? Please advice an easy way.Thanks
|
|
|
|
|
Solutions do not contain other solutions.
A solution is a collection of Projects. So, you can open the Solution you're trying to add to and just add an existing project to it. Navigate to the .proj file in the project folder you want to add to the solution.
|
|
|
|
|
David is right - it's add the project to the solution, or create a new repository for your existing "spare" solution.
I use a separate repository for each solution, which is the most sensible way - adding unrelated projects to a solution doesn't keep them separated enough, and "bloats" solutions (which can slow things down considerably if you aren't careful).
"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!
|
|
|
|
|