|
Heath Stewart wrote:
I've implemented IXmlSerializable on numerous occassions and the .NET Framework SDK says you shouldn't in .NET 1.0 and 1.1.
Hey, I've done that too, mine was because Javier asked me for a way to serialize a Hashtable to XML.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I've been looking at how to change the password of an Active Directory user in a C# application. I've seen many examples of code that create a DirectoryEntry object for the user and then Invoke("setPassword","newPassword"); . While this is useful, I can't help wondering where they are getting this information from. I haven't, yet, been able to find where I get a list of the methods I can "invoke" on a DirectoryEntry of an Active Directory User, or any other Active Directory object.
Perhaps, because I'm new to actually using Active Directory, I'm just looking in the wrong place. And, although I can do the job I need to based on the sample code I've seen, I still want to know how it is actually working.
Would someone be good enough to point me in the right direction?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
|
Thanks, I'll definitely have a look at that in more detail when I get in to work tomorrow morning.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
How are you drawing onto the picture box?
You can easily save the image with custom drawn stuff:
Image img = ...;
Graphics g = Graphics.FromImage(img);
g.DrawString(...)
g.DrawLine(...)
g.Dispose();
now you're image has the stuff you have drawn on it, so you can do:
img.Save(filename);
if you don't want to change the original image you can do:
Image img = ...;
Bitmap bmp = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(img, 0, 0, img.Width, img.Height);
... other drawing stuff
g.Dispose();
bmp.Save(filename);
|
|
|
|
|
I tried that, I keep getting an out of memory exception...
not sure what to do
You Know We Non-Stop
|
|
|
|
|
What file format are you saving it as?
There is a bug that won't let you save it to file png files.
Try using:
img.Save("file.bmp", ImageFormat.Bmp);
|
|
|
|
|
Hi
i am working with ADSI with win 2003 server in c# ... i am trying to make a user the member
of a group named "Administrators" ... my user is in an ou named "test2" ... when i start the
program ... in the end when it should add the user in Admiistrators group it give me this
error
"System.Runtime.InteropServices.COMException(0x8004005): Unspecified error"
my code is as under... it is on a button click.
private void button5_Click(object sender, System.EventArgs e)
{
try
{
DirectoryEntry dom = new DirectoryEntry("LDAP://CN=Builtin,DC=jacal99,DC=com");
DirectoryEntry group = dom.Children.Find("CN=Administrators");
MessageBox.Show("group found");
DirectoryEntry dom2 = new DirectoryEntry("LDAP://OU=test2,DC=jacal99,DC=com");
DirectoryEntry usr = dom2.Children.Find("CN=lucky");
MessageBox.Show("user found");
group.Properties["Member"].Add(new string[] {"lucky"});
group.CommitChanges();
MessageBox.Show("user added ");
}
catch (Exception ex)
{
MessageBox.Show("error coz " + ex);
}
}
ok waiting for the answer ... seea TC bye.
Mazhar Hussain
|
|
|
|
|
Using MessageBox.Show is a poor way of debugging. Insert a breakpoint into your code and step through it. On what line does the exception occur? Even just running your code in the debugger (Visual Studio .NET or cordbg.exe) with the necessary symbols (built by default for the Debug project settings) will tell you. That information will be helpful to help you solve your problem.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
I pull an image onto the picturebox control as its 'image' property. Then I draw some arrows on the picturebox (not into the image itself).
How do I save the image + the arrows I draw onto the image, out to disk?
I have tried using the BitBlt function but it seems that BitBlt always takes data from the screen-buffer as opposed to the picturebox itself. This is an issue for me because some of the picture I need is underneath scroll-bars...
Anyone have any ideas?
You Know We Non-Stop
|
|
|
|
|
Sorry, this would probably be better asked in the .NET Framework forum, but I get better responses in this one. My C# application, compiled with VS.NET 2002 Pro, which uses the .NET Framework version 1.0.xxx, runs perfectly on a machine with the .NET Framework version 1.0.xxx. However, when this program is required to run under a more recent version of the .NET Framework, I notice different functionality in certain areas of the application. The code simply cannot be anymore straightforward, it works on the same .NET version I compiled it under. My question is, if I compile this same code with VS.NET 2003, or even 2005, will the application run PROPERLY when it is running under 1.1.xxx or newer? Could there be another cause...like I said before, it runs perfect under the older version of the .NET Framework, but not so much under more recent versions. I'd appreciate the help on this...
|
|
|
|
|
.NET versions can be installed side-by-side; if you want to use the 1.0.xxx version, specify this in the configuration file for your assembly. Search MSDN if you need an example.
.NET 1.1 breaks a few 1.0 things, mostly security and remoting stuff though. If your code is as simple as you say, post some code that works differently on 1.1.
Judah Himango
|
|
|
|
|
Extending on what Judah said, look-up the <supportedRuntime> configuration element. It's only supported in .NET 1.1 and newer, since anything targeting the 1.0 framework doesn't really have a choice for backward compatibility.
There's also a lot of information about side-by-side execution in the "Programming Topics" section in the .NET Framework SDK I encourage you to read. I'd give you a link, but unfortunately I'm having connection problems to certain servers. Go figure. It's not hard finding anyway.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
I am trying to call an ActiveX DLL written in VB6 from my C# app.
The function call has a single parameter that is declared optional.
How do I call it from C#?
The VB function is:
Public Function GetTasks(Optional ByVal lngUserCode As Long) As ADODB.Recordset
|
|
|
|
|
I want to call the function without a parameter so the entire recordset is returned.
|
|
|
|
|
|
Hi All,
How I convert a text file (delimiters are blank spaces) in xml file.
luciano_rib@yahoo.com.br
|
|
|
|
|
lklkjlk wrote:
How I convert a text file (delimiters are blank spaces) in xml file.
just like you need to. :p
top secret xacc-ide 0.0.1
|
|
|
|
|
The easiest way is probably to decide on a schema (format of the xml) and then iterate through all of your text file and transform it on the fly into a string that has your schema. You can then do what you want with the XML.
store your internet favourites online - www.my-faves.co.uk
|
|
|
|
|
To expand on what Davey said, take a look at the XmlTextWriter class in the .NET Framework SDK documentation. It includes all the information you need to use it, as well as examples that should help you.
To iterate through your lines in the delimited text file, open the file in a StreamReader like so:
using (StreamReader reader = new StreamReader("file.txt"))
{
string line = null;
while ((line = reader.ReadLine()) != null)
} Like Davey said, though, the schema of the XML file really depends on what you need.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
Even if someone writes such a program, it will need numerous inputs regarding what words in the text file are tags, attributes and data. A cumbersome task.
To the very least, you will need to add '<' '>' characters in your text file, so that atleast the tags are identifiable. Rest can be assumed as data. Then you can load that file as a MS DOM document. Get MS XML DOM and see the documentation to know how to invoke the COM and load a document.
If you want to do this manually, add '<' '>' characters, rename the file to .xml and load it in XML Spy. Use the pretty-print button to format it nicely.
|
|
|
|
|
Sorry, I was not aware of XmlWriter, yes you can read up the MSDN article on XmlWriter class and I think, it is best suited for your purpose.
|
|
|
|
|
Hello, i would like to sign a xml document using a certificate stored in my machine. I have been looking for examples but in all of them framework 1.1 is used (using Microsoft.Web.Services.Security) and altough i have it, i cannot use it with Microsoft Visual Studio .NET 2002. It is possible to make the Microsoft Visual Studio to use the 1.1 version of the framework??
I only need the signed xml document to make some testing, so if it isn´t possible to sign with 1.0 using my own certificate, please tell me a program that do that (not infopath because if i check the signature always false is returned).
About the signature...it must be xmldsig.
I have a very near deadline to give my project so if you help me i will be very grateful!
Regards!
|
|
|
|
|
Read my article, XML Digital Signatures for Application Licensing[^]. It uses the classes in the .NET BCL for xmldsig. Many people - including my first work that lead to this article - use Microsoft.Web.Services.dll assembly because the documentation for the the BCL assemblies isn't so great - but it is possible. It just requires some digging into the IL in the System.Security.dll assembly.
Microsoft.Web.Services.dll, BTW, is actually from the Web Service Enhancements, or WSE. There are two versions - 1.0 and 2.0. You can read about the WSE at http://msdn.microsoft.com/webservices/building/wse/[^]. WSE 1.0 will work with both .NET 1.0 and 1.1.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
I have read your article and i have used your method to sign and to check the signature.
When you sign you don´t add the certificate info, so i add it in order to get it in the server when he receives it.
To perform the signature, it works, but when i verify it...the checksignature method always returns false...i have tried millions of things and none works.
Here i show you some code to sign:
<br />
<br />
Microsoft.Web.Services.Security.X509.X509Certificat cert;<br />
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("c:/Formtosign.xml");<br />
<br />
SignedXml sxml = new SignedXml(doc);<br />
sxml.SigningKey = cert.key; <br />
<br />
sxml.SignedInfo.CanonicalizationMethod =<br />
SignedXml.XmlDsigCanonicalizationUrl;
<br />
Reference r = new Reference("");<br />
<br />
r.AddTransform(new XmlDsigEnvelopedSignatureTransform(false));<br />
<br />
sxml.AddReference(r);<br />
<br />
System.Security.Cryptography.Xml.KeyInfo keyInfo = <br />
new System.Security.Cryptography.Xml.KeyInfo(); <br />
<br />
keyInfo.AddClause(new System.Security.Cryptography.Xml.KeyInfoX509Data(cert)); <br />
sxml.KeyInfo = keyInfo; <br />
<br />
sxml.ComputeSignature();<br />
<br />
XmlElement sig = sxml.GetXml();<br />
doc.DocumentElement.AppendChild(sig);<br />
<br />
XmlTextWriter writer = new XmlTextWriter<br />
("c:/Formsigned.xml",System.Text.Encoding.UTF8);<br />
writer.Formatting = Formatting.Indented;<br />
<br />
try<br />
{<br />
doc.WriteTo(writer);<br />
}<br />
finally<br />
{<br />
writer.Flush();<br />
writer.Close();<br />
}<br />
Now the code to verify the signature;
<br />
nodeList = doc.GetElementsByTagName<br />
("Signature",SignedXml.XmlDsigNamespaceUrl);<br />
<br />
nodeList2 = doc.GetElementsByTagName("X509Certificate");<br />
<br />
SignedXml[] signatures = new SignedXml[nodeList.Count];<br />
<br />
validSignatures = nodeList.Count;<br />
<br />
<br />
for(int i = 0; i < nodeList.Count; i++)<br />
{<br />
signatures[i] = new SignedXml();<br />
signatures[i].LoadXml((XmlElement)nodeList[i]);<br />
<br />
<br />
Certificate cerCapi = new CertificateClass();<br />
cerCapi.Import(nodeList2[i].InnerText);<br />
ICertContext iCertCntxt = (ICertContext) cerCapi;<br />
int certcntxt = iCertCntxt.CertContext ;<br />
IntPtr hCertCntxt = new IntPtr(certcntxt);<br />
<br />
Microsoft.Web.Services.Security.X509.X509Certificate cer = new Microsoft.Web.Services.Security.X509.X509Certificate(hCerCntx);<br />
<br />
<br />
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();<br />
csp = (RSACryptoServiceProvider)cer.PublicKey;<br />
if (!signatures[i].CheckSignature(csp))<br />
validSignatures--;<br />
}<br />
Your method is adapted to my necesities...but i think that is nearly the same. I get the keys not from a program, I get them from the certificate.
Thank you in advance...
|
|
|
|