|
Hi,
finally had time to check my code and found the error:
when fading in the form I did a
this.WindowState = FormWindowState.Normal
just to be sure that the form doesn´t return minimized. But I don´t need this line because the form IS never minimized and it seems to make some confusion when you fade in the form when it was maximized before. Reason seems to be that a second Resize event is raised which mixes up the size of the WindowStates.
Thanks and bye
Thomas
|
|
|
|
|
HI,
While trying to run the below code for copying a file from my system to another share folder, it returns an exception saying "Incorrect function" at the line WindowsIdentity idnt = new WindowsIdentity("domain_username", "password") in the below given code:
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Text;
using System.Management;
using System.Windows;
using System.Security.Principal;
namespace Authentication
{
class Program
{
AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity idnt = new WindowsIdentity("domain_username", "password");
WindowsImpersonationContext context = idnt.Impersonate();
System.IO.File.Copy("G:\\E-Drive\\batfiles\\java.bat", "\\\\10.200.93.93\\share\\java.bat", true);
Can any one help me out to resolve this issue?
Thanks in Advance _
|
|
|
|
|
Is the username and password in your code an example or is it what you're actually using?
|
|
|
|
|
|
Here's a clue:
Where is the author of this most likely to be? Here or OVER ON CODESOURCE!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi folks. This is probably a simple one for the XML gurus, but it has me stumped. I am trying deserialise an XML file, which is easy enough. But now I need to create objects based on an XML element's attribute, and I can't see how to do it.
Here is a simplified version of the problem. I started with a file that looks like this:
<fleet>
<auto>boss's limo</auto>
<auto<delivery truck</auto>
<auto<employee's rusty corvair</auto>
</fleet>
Easy enough to deserialise:
public class AutoClass { ... }
[XmlRoot("fleet")]
public class FleetClass
{
[XmlElement("auto")
public AutoClass[] Vehicles { ... }
}
But now, I need to change the classes around. I need a CarClass and TruckClass that inherit from AutoClass . So I created:
public class CarClass : AutoClass { ... }
public class TruckClass : AutoClass { ... }
Additionally, the file should look like this
<fleet>
<auto type="car">boss's limo</auto>
<auto type="truck"/>delivery truck</auto>
<auto type="car">employee's rusty corvair</auto>
</fleet>
But the Vehicles property generates AutoClass objects and I need the results to be of type CarClass and TruckClass . I can't downcast Vehicles[0] to CarClass (or can I?). How do I get Vehicles to examine the type attribute of the auto element and create 2 CarClass objects and one TruckClass ?
I hope that is clear - if not, let me know.
Clive Pottinger
Victoria, BC
|
|
|
|
|
|
Thanks for the speedy reply. However, I don't see how the XSD tool will help in this case. From the documentation here (http://msdn.microsoft.com/en-us/library/x6c1kb0s%28VS.80%29.aspx) it seems that the tool will simply generate code for classes based on the XML elements found. I don't see how to use it to generate a class based on an XML element's attribute.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Perhaps I need to clarify further. I would like to deserialise this XML
<fleet>
<auto type="car">boss's limo</auto>
<auto type="truck"/>delivery truck</auto>
<auto type="car">employee's rusty corvair</auto>
</fleet> into these classes
public class AutoClass { ... }
[XmlRoot("fleet")]
public class FleetClass
{
[XmlElement("auto")
public AutoClass[] Vehicles { ... }
}
public class CarClass : AutoClass { ... }
public class TruckClass : AutoClass { ... } so that
XmlSerializer s = new XmlSerializer( typeof( FleetClass ) );
TextReader r = new StreamReader( "example.xml" );
FleetClass myFleet = (FleetClass)s.Deserialize( r );
AutoClass[] myVehicles = myFleet.Vehicles; should result in myVehicles containing 2 objects of type CarClass and 1 object of type TruckClass - not 3 objects of type AutoClass .
Edit: I know I could change the <auto> tags to <car> and <truck> and collect them in the Vehicles property - but that is not the goal. The XML tag should remain as <auto> but the objects created need to be of types CarClass and TruckClass .
Is there any way to decorate the classes and properties to accomplish this?
Clive Pottinger
Victoria, BC
modified on Thursday, July 23, 2009 12:11 PM
|
|
|
|
|
i have a XML file and wanted to read value from XML and search it into the registry of system.
i can read the file but unable to find out the way to find it into the registry.
can anybody help me??
here is the code and the XML file.
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
string a = "";
XmlTextReader reader = new XmlTextReader(@"D:\REGFile.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
a = reader.Value;
string b = sk.GetValue(a);
if (sk.equals(a))
{
Console.WriteLine("Exists in Registry");
}
else
{
Console.WriteLine("Wrong");
}
break;
}
}
}
}
Console.ReadLine();
****************************XML FILE*********************
<?xml version="1.0"?>
<RegistryValues>
<Values>
<Value>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip32.exe</Value>
<Value> HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip.exe</Value>
<Value>HKCR\CLSID\{00000000-0000-0000-0000-000000000000</Value>
<Value>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip.exe</Value>
<Value>HKCR\WinZip\DefaultIcon</Value>
<Value>HKCR\WinZip\shell\open\command</Value>
<Value>HKCR\WinZip\shell\open</Value>
<Value>HKCR\WinZip\shell\print\command</Value>
<Value>HKCR\WinZip\shell\print</Value>
<Value>HKCR\WinZip\shell</Value>
<Value>HKCR\WinZip\shellex\DropHandler</Value>
<Value>HKCR\WinZip\shellex</Value>
<Value>HKCR\WinZip</Value>
<Value>HKCR\.ARC</Value>
<Value>HKCR\.TAR</Value>
<Value>HKCR\.TAZ</Value>
<Value>HKCR\.TGZ</Value>
<Value>HKCR\.TZ</Value>
<Value>HKCR\.GZ</Value>
<Value>HKCR\.Z</Value>
<Value>HKCR\.CAB</Value>
<Value>HKCR\.UU</Value>
<Value>HKCR\.UUE</Value>
<Value>HKCR\.XXE</Value>
<Value>HKCR\.B64</Value>
<Value>HKCR\.HQX</Value>
<Value>HKCR\.BHX</Value>
<Value>HKCR\.MIM</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\WinIni</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\caution</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\fm</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\Programs</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\Uninstall</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\WinZip</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\wzshlext</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing</Value>
</Values>
</RegistryValues>
sweety
|
|
|
|
|
Hi, i am very new to C#, im trying to create a file that enumerates the processes constantly, checking whether a process which is written in a txt file is running, and if so, it prints it in a .ini file, So far everythings working fine. But it only works when i open the file while the desired process is already running, thus the program has to be re-opened everytime for it to update. is there a way to make this code loop? or a mor efficiant way to get the desired effect?
Heres my code
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class Program
{
[STAThread]
[DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileString")]
private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
static void Main(string[] args)
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader("X:\\file.txt");
while ((line = file.ReadLine()) != null)
{
Process[] procs;
procs = Process.GetProcessesByName(line);
foreach (Process p in procs)
{
WritePrivateProfileString("Main", "Current Process", line, ("X:\\config.ini"));
}
}
file.Close();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
|
|
|
|
|
As you're using Windows Forms you can add a timer to the form and fire your code in the Ticks (or Elapsed, can never remember which) event of said timer. That way it will periodically check the running processes and update your ini file without the need for a loop.
|
|
|
|
|
Hey, thanks for the reply, very useful, and it was ticks... Works perfectly
modified on Thursday, July 23, 2009 11:40 AM
|
|
|
|
|
I created a method that makes use of the .Select() method so that to check in a datatable if the value is already in the data table. For 1/4 of the recordss its working but at certain point it prompts out the fllowing error
Min (14) must be less than or equal to max (-1) in a Range object.
I am getting the data from MS Access. I have changed the databases so that to check if it was only with one version but It still showed me the error. only the number 14 changed. I have checked the records of the ids that the program was stopping all and they are all good values. Can some one help on that please. it is very urgent. THAnks alot for your time and help.
|
|
|
|
|
jonhbt wrote: it is very urgent
Of course it is, all questions here are urgent to the poster. But this is a free site so... (hint don't post that again)
As to your problem can you provide the code that does the select (so your method) and some of the values where the code gives that error on?
|
|
|
|
|
Sry for that I didn't want to cause any problems the code that I am using is this
DataTable dtAllEmps = new DataTable();<br />
dtAllEmps = cetData.GetALLEmployessByDate(conString, sensors);<br />
<br />
<br />
foreach (DataRow dataRow in dtAllEmps.Rows)<br />
{<br />
if(dtCSV.Rows.Count == 0)<br />
{<br />
DataRow newRow = dtCSV.NewRow();<br />
newRow["UserID"] = dataRow["USERID"];<br />
newRow["Department"] = dataRow["DEPTNAME"];<br />
newRow["Date"] = dataRow["CHECKTIME"];<br />
newRow["Name"] = dataRow["NAME"];<br />
newRow["CheckType"] = dataRow["CHECKTYPE"];<br />
dtCSV.Rows.Add(newRow);<br />
}<br />
else<br />
{<br />
Console.WriteLine("User ID " + dataRow["USERID"].ToString());<br />
if (dataRow["USERID"].ToString() != "")<br />
{<br />
string strExpr = "UserID = " + dataRow["USERID"].ToString();<br />
Console.WriteLine("Expression " + strExpr);<br />
DataRow[] filteredRows = dtCSV.Select(strExpr);<br />
<br />
<br />
if (filteredRows.Count() == 1)<br />
{<br />
Console.WriteLine("Number of Rows " + filteredRows.Count().ToString());<br />
DataRow csvRow = filteredRows[0];<br />
DateTime csvDate = Convert.ToDateTime(csvRow["Date"]);<br />
DateTime tableDate = Convert.ToDateTime(dataRow["CHECKTIME"]);<br />
Console.WriteLine("csvDate" + csvRow["Date"].ToString());<br />
Console.WriteLine("tableDate" + dataRow["CHECKTIME"].ToString());<br />
if (csvDate < tableDate)<br />
{<br />
filteredRows[0]["Date"] = tableDate.ToString();<br />
filteredRows[0]["CheckType"] = dataRow["CHECKTYPE"].ToString();<br />
filteredRows[0]["Department"] = dataRow["DEPTNAME"].ToString();<br />
}<br />
|
|
|
|
|
I am writing the console calls so that to know what is the last value that the program is having. It is crashing in this part. The values when the program throws the exception differ.
<br />
string strExpr = "UserID = " + dataRow["USERID"].ToString();<br />
Console.WriteLine("Expression " + strExpr);<br />
DataRow[] filteredRows = dtCSV.Select(strExpr);<br />
|
|
|
|
|
Don't worry you didn't cause problems, was just a hint.
Another hint:
When posting code use the 'code block' tags, makes it easier to read the code.
As to your problem.
At what userid does the error occur?
My guess would be that since you do a 'tostring' your userid is of the type string (varchar).
If so your filter expression should be:
"UserID = '" + datarow["USERID"].ToString() + "'";
|
|
|
|
|
thanks for the advices. Regarding to the problem the values are Numbers in the database. There wasn't only one value since i tried different values. One of them was 279 which was giving problems. the strange thing is that this process runs for most of the values but at a certain point in time it stops. that is why i am confused, since all the values that are being passed are numbers.
|
|
|
|
|
Is your userid column in the datatable numeric?
If so remove the tostring (not needed here)
If not try the code I gave (but I don't think that's the problem)
jonhbt wrote: the strange thing is that this process runs for most of the values but at a certain point in time it stops
Does it always stop at the same value? or is random?
Are you using multi - threading?
|
|
|
|
|
no im not useing multi threading. The value is the same only for the set of values chosen. WHen i change the set of values by a filter from the select command in the database, the value is different.
|
|
|
|
|
When you debug and stop at the select line try doing a 'quick watch' (right mouse click)
Then run the select (dtscv.select("Userid=" + newrow["userid"]) ).
Does that work?
Is the value present or not?
Can you post your declaration of the dtscv datatable? (specifically the column declarations )
|
|
|
|
|
This is my declaration of te DataTable
DataColumn Column1 = new DataColumn("Name");
DataColumn Column2 = new DataColumn("Department");
DataColumn Column3 = new DataColumn("Date");
DataColumn Column4 = new DataColumn("UserID");
DataColumn Column5 = new DataColumn("CheckType");
dtCSV.Columns.Add(Column1);
dtCSV.Columns.Add(Column2);
dtCSV.Columns.Add(Column3);
dtCSV.Columns.Add(Column4);
dtCSV.Columns.Add(Column5);
Ill try what you suggested
|
|
|
|
|
try:
DataColumn Column4 = new DataColumn("UserID",typeof(int));
|
|
|
|
|
I think that solved the problem. I stil have to takle the performance issue, but THANKS alot for your help
|
|
|
|