|
I have a Stream of bytes from a file, I wish to cast the byte array into various data types eg int doubles etc( no I cannot do this at the file read stage due to the nature and format of the data), but under compilation I either get on the data from the first byte or complier warnings being 'unable to cast byte[] to int'. How can I convert an array of bytes to another data type eg a 2 byte array to an int.
Thnaks in advance
|
|
|
|
|
I have a RichTextBox. I'd like to know the current position in this control (line & column). If a have a text with tabs, i need to know the size of each tab
PLEASE HELP ME !!!
Thanks.
|
|
|
|
|
How can I convert a long into a date in C#?
For example the number 37634 is equivalent to 13/01/2003.
In Vb6 I could write:
Dim d As Date<br />
<br />
d = CDate(37634)
and d would then hold 13/01/2003
|
|
|
|
|
There are two ways to achieve this... You can use Convert.ToDateTime(37634) or DateTime.FromOADate(37634).
Chris
|
|
|
|
|
Cheers
|
|
|
|
|
Hi all,
Just want to see if there is much interest for an article on how to save out high quality gif images in C#. I've written some code that saves out an image in gif format (indexes and selected palette colours) with different options for how the colour palette is selected: standard (default .net implementation), web safe, most popular and octree. The octree method is by far the best and fastest with very similar results to photoshop. Let me know and I'll knock something up in the next couple of weeks.
Regards
Andy
-----------------------------
Try my Batch Image Processing Software Read my DirectX 8 Tutorials
|
|
|
|
|
|
Yes!
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I'd be very interested in the article. I'd be especially interested in the implementation details of the octree algorithm.
|
|
|
|
|
I'm a VB developer trying to learn C#. I have a problem. I'm not able to access public methods of one form in other form.
Form frm = new Form2();
frm.Initialize();
It is giving me compile time error
|
|
|
|
|
A few suggestions :
- from the code above, you are creating an object of type Form2 , and then store its reference to a variable of type Form . Although this could be ok, it's likely you are misusing the object types. Use this instead : Form2 frm = new Form2() .
- to make sure a method can be called from the outside, just add the public attribute on the left of the return type. For instance, public void Initialize() { ... }
|
|
|
|
|
Basically i have created a windows service for the purposes of logging events, exceptions etc to a central database. The windows service gets the objects (ie info object, warning object, excepiton object etc) from a MSMQ queue. Since I wanted to deploy the whole thing a bit easier (in case I needed to move it), I created a web service so that my other apps call the webservice with the message to log, and the webservice takes care of putting the object into the queue which is monitored by the windows service.
Heres my question (finally). What are the rules for objects being deserialized and serialized, with respect to does the assembly doing the serializing need to know of the types it it serializing, or can it just know of the base type etc?
TIA
Andy
He who knows and knows that he knows, is wise; follow him
He who knows and knows not that he knows, is asleep; wake him
He who knows not, and knows that he knows not, is simple; teach him
He whoe knows not and knows not that he knows not, is a fool; kick him
|
|
|
|
|
I have some code that reads from a NetworkStream, retrieving both standard strings as well as binary data. The following code works:
connection_ = new TcpClient(host, port);
connection_.ReceiveTimeout = 30000;
stream_ = connection_.GetStream();
bufStream_ = new BufferedStream(stream_);
reader_ = new StreamReader(stream_, Encoding.GetEncoding("iso-8859-1"));
string str = reader_.ReadLine();
byte b = (byte)bufStream_.ReadByte();
But it's a little weird because the reader goes directly against the network stream for reading full lines as strings, but it goes through the buffered stream when reading individual bytes. Even though this works, I tried the following change:
reader_ = new StreamReader(bufStream_, Encoding.GetEncoding("iso-8859-1"));
But this doesn't work at all. When it gets to the ReadLine, it blocks indefinitely. Could this be a bug in BufferedStream? I'm using .Net 1.0, by the way.
|
|
|
|
|
I got around this problem by writing my own "ReadLine" for the buffered stream, eliminating the need for the StreamReader. Here it is, if you are interested. Please excuse the use of "goto", but it was the most natural (and efficient) way to write the code:
private string ReadLine()
{
StringBuilder sb = new StringBuilder();
byte b;
<BR>
p0:
b = (byte)bufStream_.ReadByte();
if (b != '\r')
{
sb.Append((char)b);
goto p0;
}
<BR>
p1:
b = (byte)bufStream_.ReadByte();
if (b != '\n')
{
sb.Append((char)'\r');
if (b == '\r')
{
goto p1;
}
else
{
sb.Append((char)b);
goto p0;
}
}
<BR>
return sb.ToString();
}
|
|
|
|
|
Is there a preference for Windows Forms programmers between overriding On{EventName} vs. adding an EventHandler for the {EventName} event?
For instance, override OnClick(...) vs. Click += new MouseEventHandler(this.ClickHandler).
Is either way more proper or efficient, etc.? I can understand that in certain cases, it makes sense to override OnPaint if you don't want the base OnPaint handler called, and things like that.
Thanks,
Arun
|
|
|
|
|
Generally speaking, it is better to override the On{EventName} methods first. The first reason is that the On{EventName} method will be called before the corresponding event is fired anyway, and the second reason is that overriding the method is more efficient than intercepting the event. Of course, that advice goes out the window if you aren't deriving from the class that is issuing the event(s). In that case, you will need to intercept the event itself.
|
|
|
|
|
I use a function from DLL that returns a char**:
extern char** GetNames();
Here my PInvoke declaration:
[DllImport("mydll.dll")]
static extern IntPtr GetNames();
So, I would like to know how I can get all strings in IntPtr?
Thanks!
|
|
|
|
|
There was a thread in this forum a couple of days ago called "Marshalling char**", which explained exactly that.
|
|
|
|
|
Can I make my own class that can be persisted to a resource and read back from it using ResourceManager.GetObject()? I ought to know this by now, but the only way to know is to find out. I've looked all over but haven't found any info yet. Does anyone know how it's done?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi...
I have some problems. I need to reboot my FTP service on my server trough an ASP.NET UI. I've tried to use Impersonate to gain administrator access, and use Processes to execute the command. This won't work, since impersonated access aint interhited to the process.
The next thing we tried, was to use some Windows API calls like CreateProcsessAsUser and CreateProcessWithLogonW, witch worked localy in a console app. (Used task manager to be sure the right user was executing the process). BUT, when using the exact same code, trough ASPNET, the ASPNET account was the account executing the .exe file.
So, witch options do i have? Anyone got file execution trough ASP.NET to work? This is driving me crazy.. Would love to se some code samples from people executing .exe files trough ASP.NET using C#.
*frustrated* confused:
|
|
|
|
|
A suggestion is to create a windows service. Doing so, you decide (service properties / LogOn tab) under which logon the service is running. Then build an ASP.NET page which awakes the service on demand.
|
|
|
|
|
Agree..
This was what i was thiking avbout, BUT, i have one concerne, witch is that the problem is not my code but BulletProf FTP server. The reason is that in the middle of my frustration a system SP in SQL Server came in mind: xp_cmdshell, witch allows
you to execute shellcommands on the server. I created a .BAT script rebooting the server. If i double clicked the .bat file, it rebootet my FTP server, but, if i simply typed "EXEC xp_cmdshell 'c:\myscript.bat'" nothing happened. This is realy strange!
I have never written any windows services, but i was thinking that this might be the solution. Once i have the service up and running, i can set permissions to the service, and access it trough ASP.NET?
Am i the only one experiencing these problems executing .exe files on the server..?
Tnx for the help so far..
PS! Other suggestions on how to reboot my FTP server is greatly appreachiated.
(Sorry my bad english, my head is getting tired, and my mother thounge is Norwegian..)
-Jonas
|
|
|
|
|
LogonAsUser maybe?
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Not sure if the WINAPI methods are the key. Since, the CreateProcess... methods worked just fine in a console app, but in a asp.net app, it simply wouldn't execute correctly. I did manage to execute the command as Administrator (according to the Task Manager) but, it didnt work... Anyone know if Bulletproof FTP Server have any issues like this?
Jonas
|
|
|
|
|
BulletProof FTP server have some inbuilt events. I use the OnHour event to execute a .bat file reloading the ini file.
But, i still would like to know how to achive this codewice....
Tnx for the help.
|
|
|
|