|
If you do Seek on the BaseStream , remember to call DiscardBufferedData on the StreamReader . Otherwise, you'll get the rest of the buffered data before you get the data from the new position in the stream.
It doesn't look like you can turn this buffering off.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Your solution suggests using BaseStream, property of StreamReader class. But I don't only need to deal with files, I need to deal with strings also. The StreamReader class has a BaseStream property but the StringReader class does not. What do you suggest in this case?
Moreover, I would like to ask you whether the "alternate way" that I've posted above is right according to you in this situation or not.
Thanks,
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
There's almost never a "right" way, just good and bad ways. Your alternative - if it works - isn't bad and seems to be pretty efficient. That's what counts.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Sorry, that was supposed to be "efficient", not "inefficient" ( I use the latter far more often here in this forum ). Context clues should've told you that, but thanks for the low vote anyway.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can i create a split window with the LHS consisting of various tabs and on the RHS have buttons that will jump to different tabs? How would I go about doing this?
|
|
|
|
|
Hi,
you can change the tabs on the fly by handling the button click event. In the delegate you need to write :
TabControl1.SelectedIndex = 0;
and that will do the magic...
Note : the int value starts from 0.give the index of the tab you want to select. There is another property SelectedTab. If you have the indivisual tab objects , you can use them.
regards,
aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
IS there a way of converting a struct to an byte array.
My struct has two fields an int in the form of an enum and a string
thestruct
{
enum_Do_something; // goes to a switch case with a list of commans.
string command; // what to do
}
is there a way to just convert this to an byte array? or should i just send each field. This is for a server/client apps.
modified 16-May-21 21:01pm.
|
|
|
|
|
If both the client and server are .NET applications, you could always use a BinaryFormatter (or any formatter, using the proper Encoding class if using text I/O) which would be much easier. You could just write to the NetworkStream for the TcpClient , for example, using this method.
One way is a bit of a hack, but should work:
int size = Marshal.SizeOf(typeof(thestruct));
IntPtr ptr = Marshal.AllocHGlobal(int);
byte[] buffer = new byte[size];
Marshal.Copy(ptr, buffer, 0, size);
Marshal.FreeHGlobal(ptr);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My connection is between a OC and a pocket PC, so im using the .Net Compact framework, i should have posted that.
Well then i got the thinking, pulling weird stuff out of my head, "what if i cast the struct to an object and send the object.ToSting() ?, no that will never work"
But i still tried it, so i just threw something together:
aStruct qwerty = new aStruct( 35, "Football");
object wed = (object) qwerty;
aStruct ytrewq = ( aStruct ) wed;
Console.WriteLine( ytrewq.aInt.ToString() );
out of dumb luck it worked, strange. Well is this way bad? i havent tried to send it yet (ByteArrayData = Encoding.ASCII.GetBytes( wed.ToString()), but it worked.
modified 16-May-21 21:01pm.
|
|
|
|
|
i go ahead of myself ( i do that alot) yea the above code works but not the .ToString i should have known that
modified 16-May-21 21:01pm.
|
|
|
|
|
No, that's not a good way because you can't as easily parse the string back into a struct. ToString overrides are meant to represent an instance of a class or struct. Some classes won't output near enough information to reconstitute it, and any struct that overrides ToString (I do it quite a bit) won't have enough information either.
Since you're using the .NET CF (which would've been nice to know before writing all that stuff that isn't supported in it ), you're definitely in a bind - but not an impossible solution (I don't know the meaning of it...just improbable solutions ).
The best way is to do basically what a formatter would do - use reflection to get the public and private fields of a structure. It you don't have any nested compex types, this is pretty much all you'd have to do. Then, for each type check if it has a TypeConverter using TypeDescriptor.GetConverter and call ConvertToString on that. That will often give a more accurate representation as a string, and ConvertFromString can reconstitute the member Type. Be careful, though - while most types you'd typically find in a struct have a TypeConverter , many types throughout the .NET Framework don't.
See the TypeConverter and TypeDescriptor class documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
I wanted to find out if we can control the 'min occurs' and 'max occurs' values in a the wsdl that is generated automatically when ?WSDL is used. I am wondering if there is some attribute that we could use with the webservice method code itself.
Thanks!
|
|
|
|
|
If you're looking to change the WSDL that is generated, see the System.Web.Services.Description namespace in the .NET Framework SDK. There are ways to modify the WSDL, but unless the client understands what to make of those changes, it really doesn't matter. The other option is to write-out the WSDL yourself, which isn't unheard of (several articles on MSDN deal with this). As an alternative, you could grab the auto-generated WSDL once and modify it.
As far as attribute parameters in either of the System.Web.Services sub-namespaces or the System.Xml.Serialization namespace, there's none that I've seen or that are documented.
You might check out the Web Service Enchancements from Microsoft at http://msdn.microsoft.com/webservices/building/wse/default.aspx[^]. It implements several of the Web Services specs and recommendations and may include what you're looking for. I've really only dealt with the WS-Encryption and WS-Signature portions of it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a tutorial for all the C# keywords in a way that a n00b can understand? I think MSDN is little confusing and not much example on each keywords.
Also, I heard that using C# with OpenGL is easier to learn and faster than Managed DirectX, is there a good online resource site that contains C# with OpenGL tutorials for n00bs?
http://www.shintasoft.com
Bring you English Version Super Robot Wars games
|
|
|
|
|
|
As Heath has pointed out to you, MSDN is the place you need to visit for keyword docs.
Regarding OpenGL: unless there is some kind of managed interface, you are going to be better off with Managed DirectX as a noob.
HTH
R.Bischoff .NET, Kommst du mit?
Great Freeware -> Abilon - Rss Reader | Zip Genius | SmartFTP
|
|
|
|
|
there is opengl for C#, it's called Tao Framework, i don't like msdn, it's not n00b friendly ^_^;
i need a n00b source for the C# keywords tutorials by examples X_x;;; don't tell me msdn cuz i already know where to find it >_<
http://www.shintasoft.com
Bring you English Version Super Robot Wars games
|
|
|
|
|
Well, it's the most complete documentation on C#. Other then that, try searching Amazon for beginning C# books.
RageInTheMachine9532
|
|
|
|
|
Hi, I have CCW written and I want to make it to be portable( to be running on different PC without need to recompile). I need to make some kind of installation program to registry this COM when it's brought on new PC.
Question: 1. is it possible?
2. if it is possible - is there any code sample or tutorial for it?
Thanks
|
|
|
|
|
Yes it is possible. Your installer should run "regasm.exe /codebase assembly.dll" on the target machine when the assembly has been copied over. This assembly can be found in the "%WINDIR%\Microsoft.NET\Framework\v1.x.xxxx" directory of the target machine, if .NET is installed. Replace "x.xxxx" with the version you want to target, or detect the latest version of .NET.
How you do it depends on what installer you use. You could use the Windows Installer project in VS.NET to do this. This allows you to also get the path of the file easily what it will be when copied to the target machine.
On a side note, make sure you followed good COM guidelines, like using fixed GUIDs using the GuidAttribute for your interfaces and classes, and never use auto-generated class interfaces. Also specify ClassInterfaceType.None on your class, explicitly define your class interface, and implement that as the first interfaces. Microsoft doesn't do this in their samples in the .NET Framework SDK, but they do recommend it elsewhere and as someone with many years of COM experience I can tell you that you must follow good COM guidelines or you'll run into problems, such as never changing a released interface. Always derive a new one, append "2", "3", and so on for each new version (just like you'd see in various API documentation on MSDN).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there an easy way to delete the (old) last lines of a multiline TextBox? Cos now I have to set the MaxLength to a huge number...
Thanks!!!
|
|
|
|
|
I'm still not all that familiar with Windows Forms, although I've studied it. Can't you do something like this? (Warning: poorly-designed code)
public static void RemoveTopLines(TextBox textBox, int linesToRemove) {
if (textBox == null) {
throw new ArgumentNullException();
}
else if (linesToRemove < 0) {
throw new ArgumentException("Invalid line count (" + linesToRemove + ")");
}
string[] lines = textBox.Lines;
int currentLineCount = lines.Length;
int newLineCount = lines.Length - linesToRemove;
if (newLineCount < 0) {
newLineCount = 0;
}
string[] newLines = new string[newLineCount];
if (newLineCount > 0) {
Array.Copy(lines, linesToRemove, newLines, 0, newLineCount);
}
textBox.Lines = newLines;
}
|
|
|
|
|
Jeff Varszegi wrote:
Warning: poorly-designed code
I beg to differ This is most likely the best way to make large changes to lines.
|
|
|
|
|
Thanks! I mostly mean that I didn't take the time to think about synchronization issues, and I didn't spend the normal half hour agonizing over every parameter name, etc. I also didn't test whether it'd be faster just getting the text as a string, and calling IndexOf repeatedly to skip past the indicated number of new-lines in the string; that might be faster, but I didn't have the time.
|
|
|
|