|
thanks for your help
but i should deserialize font and alignment of my textbox with reader.value ,too
please tell me what i do?
thanks.
|
|
|
|
|
You should be using TypeConverter s for the whole thing, otherwise use ToString . Many classes can't be reconstituted from their ToString representations. If you use XmlSerializer as I mentioned, this is all done for you. But, if you insist on doing things the hard way, you can get a TypeConverter reference for each type using something like this:
TypeConverter converter = TypeDescriptor.GetConverter(theText.Left);
xw.WriteAttributeString("X", converter.ConvertToString(theText.Left));
converter = TypeDescriptor.GetConverter(theText.Top);
xw.WriteAttributeString("Y", converter.ConvertToString(theText.Top));
xw.WriteEndElement();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
the serialize code:
xw.WriteAttributeString("Font",theText.Font.Name.ToString());
and it is deserialize code,i use convector but it dosent work properly.
FontConverter ff=new FontConverter();
theTextBox.Font=(System.Drawing.Font )ff.ConvertFromString(reader.Value );
what i do?
thanks.
|
|
|
|
|
You don't instantiate the FontConverter itself, which is documented if you bother to read it. Always use TypeDescriptor.GetConverter .
And instead of saying "doesn't work properly" - which is has in my experience - you might want to be more specific about what's not working, since I can't really help if I don't know what the problem you're having is.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for reply
i use from TypeConvector in my code but c# dosent know it.
my serialize or save code is:
xw.WriteStartElement("TextBox");
xw.WriteAttributeString("X", theText.Left.ToString());
xw.WriteAttributeString("Y", theText.Top.ToString());
xw.WriteAttributeString("Width",c.Width.ToString());
xw.WriteAttributeString("Height",c.Height.ToString()); xw.WriteAttributeString("Value", c.Text);
TypeConverter converter = TypeDescriptor.GetConverter(theText.Font); xw.WriteAttributeString("Font", converter.ConvertToString(theText.Font))
xw.WriteAttributeString("TextAlign",theText.TextAlign.ToString());
xw.WriteAttributeString("Backcolor",c.BackColor.ToArgb().ToString());
xw.WriteAttributeString("Forecolor",c.ForeColor.ToArgb().ToString());
xw.WriteEndElement();
and my deserialize or read code is:
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i); switch(reader.Name)
{
case "X":
theTextBox.SetBounds(Convert.ToInt32(reader.Value),
theTextBox.Top, theTextBox.Width, theTextBox.Height);
break; case "Y": theTextBox.SetBounds(theTextBox.Left,
Convert.ToInt32(reader.Value), theTextBox.Width,theTextBox.Height); break;
.. case "Font": TypeConverter ff = TypeDescriptor.GetConverter(reader.value);
theTextBox.Font=(System.Drawing.Font)ff.ConvertFromString (reader.Value );
break;
case "Backcolor":
theTextBox.BackColor= Color.FromArgb(Convert.ToInt32(reader.Value));
break;
please tell me,what i do for my deserialize code?
|
|
|
|
|
So what exactly is the error? Be specific. What's the exceptio type, if any? What's the exception message read.
And as I said originally, you really should be 1) using a TypeConverter for everything (this is what the XML Serialization routines do), or 2) just using the XmlSerializer , which takes care of all this for you. All that code you've typed could be wrapped up into 3 or 4 lines. use what's available in the BCL unless you have a good reason for re-implementing everything yourself.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Also take a look at BinaryFormatter and SoapFormatter classes which can be used to serialize objects to a stream e.g. a filestream.
They cannot be used to serialize a whole TextBox instance as it's not marked as serializable, but they work with specific fields as most of them are simpler types which can be serialized.
www.troschuetz.de
|
|
|
|
|
Hi
I want to reload a page with a button. The page I wish to reload lies in an i frame, the button that I wish to use to reload lies in another i frame. I have this code in the *.aspx file and it works. The code lies behind a link, and I wish to have it behind a button.
href="javascript:location.reload()" target="sub_top"
can I use this code in code-behind? how do I do this?
Thanks!
-- Evil geniuses for a better tomorrow --
|
|
|
|
|
No, you can't use that code in the code-behind. Since the code-behind will regenerate the entire HTML page anyway, you'll just end up loading the entire frameset. You're better off putting that code in the onclick handler of a button.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Code project C# guru’s ,
I am attempting to implement RFC 2095 ( http://www.ietf.org/rfc/rfc2095.txt ) I’ve found what I believe is an error in the crypto library for C#.
Now be kind I’ve been coding C# for exactly 1 week , and it has been about 7 years since I coded in production . The last time I coded was in VI on Unix. This is just one of the methods I’m attempting to implement in this project. The rest of the project includes an SMTP server, and verification schema.
I’m implementing the procedures in a C# program found in RFC 2095, and using the CRAM algorithm found in http://www.ietf.org/rfc/rfc2104.txt . The test data strings found in RFC 2095 include a share key string “tanstaaftanstaaf” and the challenge “<1896.697170952@postoffice.reston.mci.net>” these test values should produce according to the test in the RFC the hashed hex output “b9 13 a6 02 c7 ed a7 a4 95 b4 e6 e7 33 4d 38 90” .
In the following program from the MSDN code library (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconextendingkeyedhashalgorithmclass.htm) I get the following output from the output string B9 13 A6 2 C7 ED A7 A4 95 B4 E6 E7 33 4D 38 90 on the test case. And, of course the fourth hex pair has dropped the leading zero .
That would be wrong according to the Keyed MD-5 hash algorithm . The leading zero should be left in place. From my feeble attempts at debugging it looks like it is either the output of the HEX according to Microsoft or internal to the crypto library. Either way how do I make sure that it does not drop that leading zero ?
Thanks in advance,
Sam
From the MSDN Code Library with RFC 2095 Edits
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Security.Cryptography;
public class TestHMACMD5
{
static private void PrintByteArray(Byte[] arr)
{
int i;
Console.WriteLine("Length: " + arr.Length);
for (i=0; i<arr.length; i++)=""
="" {
="" console.write("{0:x}",="" arr[i]);
="" console.write("="" ");
="" if="" (="" (i+9)%8="=" 0="" )="" console.writeline();
="" }
="" (i%8="" !="0)" public="" static="" void="" main()="" create="" a="" key.
="" byte[]="" key1="{0x0b," 0x0b,="" 0x0b};
="" pass="" the="" key="" to="" constructor="" of="" hmacmd5="" class.="" hmac1="new" hmacmd5(key1);
="" another="" added="" test="" case="" for="" rfc="" 2095
="" key2="System.Text.Encoding.ASCII.GetBytes("tanstaaftanstaaf");" hmac2="new" hmacmd5(key2);
="" encode="" string="" into="" byte="" array,="" hash="" array,
="" and="" print="" screen.
="" data1="System.Text.Encoding.ASCII.GetBytes("KeyString" printbytearray(hmac1.computehash(data1));
="" 2095
="" data2="System.Text.Encoding.ASCII.GetBytes("<1896.697170952@postoffice.reston.mci.net">");
PrintByteArray(hmac2.ComputeHash(data2));
}
}
public class HMACMD5 : KeyedHashAlgorithm
{
private MD5 hash1;
private MD5 hash2;
private bool bHashing = false;
private byte[] rgbInner = new byte[64];
private byte[] rgbOuter = new byte[64];
public HMACMD5 (byte[] rgbKey)
{
HashSizeValue = 128;
// Create the hash algorithms.
hash1 = MD5.Create();
hash2 = MD5.Create();
// Get the key.
if (rgbKey.Length > 64)
{
KeyValue = hash1.ComputeHash(rgbKey);
// No need to call Initialize, ComputeHash does it automatically.
}
else
{
KeyValue = (byte[]) rgbKey.Clone();
}
// Compute rgbInner and rgbOuter.
int i = 0;
for (i=0; i<64; i++)
{
rgbInner[i] = 0x36;
rgbOuter[i] = 0x5C;
}
for (i=0; i<keyvalue.length; i++)=""
="" {
="" rgbinner[i]="" ^="KeyValue[i];
" rgbouter[i]="" }=""
="" public="" override="" byte[]="" key="" get="" {="" return="" (byte[])="" keyvalue.clone();="" }
="" set="" if="" (bhashing)="" throw="" new="" exception("cannot="" change="" during="" hash="" operation");
="" (value.length=""> 64)
{
KeyValue = hash1.ComputeHash(value);
// No need to call Initialize, ComputeHash does it automatically.
}
else
{
KeyValue = (byte[]) value.Clone();
}
// Compute rgbInner and rgbOuter.
int i = 0;
for (i=0; i<64; i++)
{
rgbInner[i] = 0x36;
rgbOuter[i] = 0x5C;
}
for (i=0; i
|
|
|
|
|
The bug is in your code. If MD5 didn't work once, it wouldn't work for any plain text.
Use Console.Write("{0:X2}", arr[i]) instead of just using "{0:X}" for the format specifier. This makes sure that 2 chars are used per bit.
Also, it's faster to use arr[i].ToString("X2") in this case, and this is typically true when you need to format only one value. Why? Because using Console.Write (or any of the formatting methods) instantiates a StringBuilder and does some having parsing to eventually call Byte.ToString(string, IFormatProvider) , which you could just do directly here (though you don't need to pass an IFormatProvider in this case).
It's best you don't claim bugs, especially when you've only been programming C# for 1 week. Check out the documentation, search the 'net for similar findings, and ask someone to verify (like on this forum), then declare you've found a bug and report it to the proper channels.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
It's best you don't claim bugs, especially when you've only been programming C# for 1 week. Check out the documentation, search the 'net for similar findings, and ask someone to verify (like on this forum), then declare you've found a bug and report it to the proper ch
First. Thank you very much.
Second. I was using the example code from Microsoft on their implemenatation of the correct code (which is still obviously wrong according to the RFC). I did check the net for this very topic (very thin and obscure task). I did ask somebody to verify but they were looking at the entire code and easily missed the problem.
Third. It was an obvious small error on my part that I should have caught. I just never figured that Microsoft would provide a sample of an RFC that wasn't compliant. That is exactly why I thought to ask the kind folks here at Code Project for help.
Fourth I wasn't claiming a bug and was looking for the exact validation you provided in that the Microsoft code as supplied was wrong and not something deeper. They should change that one item to make it RFC compliant.
Fifth. Thanks again. Sorry if you thought I was calling your baby ugly. Haven't you ever beat your head on the keyboard looking at the obvious to somebody else while completely missing the EASY! answer?
Again thank you very much for the help.... Now to finish the project. And, I think C# is pretty darn nifty......Thanks again, and again.... Really...
--------------------
Sam
|
|
|
|
|
The samples in the documentation is riddled with bugs. Look at it - hopefully it helps you to understand if the class documentation doesn't - but never copy it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
selil wrote:
static private void PrintByteArray(Byte[] arr)
{
int i;
Console.WriteLine("Length: " + arr.Length);
for (i=0; i {
Console.Write("{0:X}", arr[i]);
Console.Write(" ");
if ( (i+9)%8 == 0 ) Console.WriteLine();
}
if (i%8 != 0) Console.WriteLine();
}
This is happening because the format specifier in {0:X} is dropping the leading zero. The value is represented with the leading zero (obviously, since the value is 2), but the leading zero is just not printed.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
THANK YOU! Too!
I'm working on a coding project for a class (500 level course) to implement a secure email (schema) login procedure. I was looking to learn C# since I had heard about how easy it is to utilize for fast development. The hardest thing to learn has been where certain libraries are located. Doing the windows programming was a breeze, but I beat my head trying to figure out where this particular issue was (I implicitly trusted the MS code). I used to do a lot of programming in VC++, and Java and everybody seems to think C# is the wave of the future (RFC 2095 and RFC 2104) so to increase the level of difficulty I switched. So I'm writing an IMAP server and IMAP mail client for my first C# project. I have three days to complete the assignment in a new language, against sketchy RFC's, and it must be fully functional by tomorrow morning... Yee haw.
Thanks again!
--------------------
Sam
|
|
|
|
|
We know we can use propertyGrid to configure object,but how can we use it to configure html component's property such 's property.This condition is like ASP.NET'S develop entironment??
ok
|
|
|
|
|
You mind elaborating a little? Are you trying to assign or change HTML for a control? Why not just switch to HTML view?
If this question is specific to ASP.NET, please post it in the ASP.NET forum. If you're asking about design-time support, read Enhancing Design Time Support[^] in the .NET Framework and ask about any specific questions you have here.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
can anybody give me some idea how to write code for file transfer using xmodem protocol.
|
|
|
|
|
If you want to write a client, then you'll need to study the XMODEM protocol. A quick search[^] on google turned up many references to the specifications.
If you just want to use XMODEM, then you'll need to search for a library. A quick google search[^] turned up several possibilities.
See how handy google is when you need to find things? A search engine is a much better way of finding resources for what you already know.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Does ANYONE know of a way to access the drag image created by the drag source (in this case Windows Explorer) so the same image can be displayed when dragging over the target control? It's easy enough to drag files from Explorer to another app since the FileDrop flag allows you to access a string array of file names. However, I'm trying to display the same drag image created by Explorer in order to give the user more meaningful feedback while dragging.
All I've seen so far is that the IDragTargetHelper and IDragSourceHelper interfaces are helpful for shell drag operations. Of course, those interfaces are as well documented as everything on MSDN....
I'm desperate for an answer at this point, so anything helps, even if it seems elementary!
Thanks!
|
|
|
|
|
I find them and everything else on MSDN well documented enough.
There is no functionality in the .NET BCL to help you - you will have to interop those interfaces (or find a library that does) and use the COM implementation of drag-n-drop. The IDataObject interface is similar to COM's interface and is eventually marshaled as COM's IDataObject , and Control.DoDragDrop uses the shell's DoDragDrop function.
The interoperability between drag-n-drop/clipboard formats and structures in .NET and COM has been discussed extensively in the past. I have accomplished this and made use of COM's implementation to use other storage mediums and have directed another person in it as well.
If you want to know more, click "Search comments" directly above the the message board and search for various keywords, like "STGMEDIUM" and/or "FORMATETC".
Otherwise, read the MSDN documentation and related links and try to figure it out. I didn't have any problems when I learned many, many years ago when MSDN wasn't nearly as helpful as it is now - and it certainly beats reading *nix man pages!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You’re making the assumption that assumption that I’m proficient in C++. Frankly I’m no further now that I was before. I’ve found plenty of articles that state the COM IDataObject interface is necessary, but I’ve found nothing that discusses it in VB or C#. I searched the keywords you suggested, but there’s still little that shows or explains how one might implement this in a language other than cpp. Can you perhaps elaborate or at least point to an article that has substance to it?
|
|
|
|
|
I assumed nothing - just told you what needs to be done. If you don't understand it, you can always read about it in the Platform SDK and .NET Framework SDK available at http://msdn.microsoft.com/library[^] - that's how I learned some time ago.
I have a todo item for such an article on my list, but have little time to work on stuff like that - especially since this is a rather complicated solution.
If you don't want to research the solution, then consider that you really don't need it - it's only for glit; not having a bitmap drag image won't impeed functionality at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've already spent 3 weeks trying to find a suitable solution, including every article I can find on the platform SDK... but, like I said, most every solution is in c++ and would be extremely difficult to port to c# or vb because of the MFC underworkings and abilities c++ has to do things like creating co-classes. The reason I'm pursuing it at this point is that the project itself is done (shy of marketing) and this is the last step. You're right, it won't impeed functionality, but I also wouldn't drive a car withouth a front windshield if I had a choice
|
|
|
|
|
If you can't or don't want to interop and P/Invoke all that's required in C#, you're forgetting a good alternative: write a mixed-mode Managed C++ assembly and port your drag-n-drop code to that. Using a mixed-mode (as opposed to pure; the difference being what APIs you use) assembly gives you full access to unmanaged and managed APIs.
What do you want me to tell you? As I said, it's a complex problem to solve and I'm a very busy person. I'll get around to an article when I can, and I haven't seen a decent one regarding this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|