|
hi friends.
I have converted a doc or image file to byte code by this code.
-------------------
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
int length = (int)fs.Length;
byte[] content = new byte[length];
fs.Read(content, 0, length);
--------------------
Now i want to convert this "content" i.e array of byte to actual file.
at the time of conversion in which object should i store the output (because i don't know the type of file i had converted to byte code).
How to do this.
(basically i m sending a file(image,doc,txt etc) from one machine to another remotely).
Hope you understand what i want to do here.
Thanks lot.
|
|
|
|
|
Just use Write method instead of Read and pass the byte array you have to it.
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write);
int length = content.Length;;
fs.Write(content, 0, length);
|
|
|
|
|
and how to convert it back into a file??
|
|
|
|
|
It will be a file. Just don't forget to close the stream when you've done writing to it. Also, you might want to create the file first if it doesn't exists
|
|
|
|
|
I think your question related to knowing what type of file to save the byte stream as on your target machine? mr. Dalakishvili has told you how to save ti to your target path, all you need do is keep the same extension and it should work fine.
|
|
|
|
|
-------------------
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
int length = (int)fs.Length;
byte[] content = new byte[length];
fs.Read(content, 0, length);
--------------------
ah, a long way to convert a file into byte[],
try
byte[] mybytes = File.ReadAllBytes(filePath);
to write byte(back to file)
File.WriteAllBytes(filePath, mybytes);
hope this will help
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi
Can someone please help me... It's seem like there is not a single way to get the column size from a dataset, table, datarow from SQL/Oracle in .Net using C# or VB
Thanks in advance
|
|
|
|
|
|
how to create folder in run time.
hai when i register my details create a folder in my name using .net with c#.if u know the code replay me.
modified on Wednesday, February 27, 2008 6:17 AM
|
|
|
|
|
|
thank u for your replay.
but i need .net with c# coding.
|
|
|
|
|
sugunavathysubramanian wrote: thank u for your replay.
but i need .net with c# coding.
And he gave you a link to the information that will aid you in writing the code. Part of being a developer is being able to research topics, understand it, then use what you learned to write the code you require. People here don't do your work, they help with specific problems. Tty to write the code yourself, and if you have a specific question, reply on THIS THREAD.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
|
Hi All,
I am handling keypress event for a RichTextBix control on my windows form. But, when i press a key on it, why its entering two times into keypress event code instead of once.??
I have added event handler only once on my form.
could anyone please suggest me how can I overcome this problem?
Thanks,
Durga.
Strength is life, Weakness is death.
--- Swami vivekananda
|
|
|
|
|
The delegate that handles the event raised has the invocation list of the methods to be called. It could be a reason that the code where the event is registered is called twice in the code execution, so check that out; the statement '+=' should be called only once when the form is loaded and the controls are created and added to it.
Muhammad Talha
|
|
|
|
|
Hi,
thanks for the reply. I'm sorry that it was my problem i added the event handler twice inadvertently.
Strength is life, Weakness is death.
--- Swami vivekananda
|
|
|
|
|
I am doing some asynchronous operation(Webclient.DownloadFileAsync() ) which is working on a separate thread. This will raise some events when the download process finished. Is it possible to stop the current thread until these events are fired ? Inside the event handler, I need to resume the thread. Any idea's ?
|
|
|
|
|
Hello,
If you mean Stop and Start the MainThread and you have the instance of the main Window for example.
You could call something like this from your working thread.
private void StopThread()
{
if(InvokeRequired)
{
Invoke.....
return;
}
Thread actThread = Thread.CurrentThread;
actThread.Suspend();
}
All the best,
Martin
|
|
|
|
|
Hi,
I am doing unit test with NUnit. The application which I am testing is a downloader which downloads files from remote server. So once the downloading finishes, I need to assert the file size. But since the download process is happening in the other thread, NUnit GUI is not waiting until download completes. Hence I was not able to test the events. I managed it by running the download class in another thread, just below to that I used Thread.Sleep() to make NUnit GUI wait for some time. By this time, the thread which I created will finish the download work and calls all events. So I can test the events too.
Anyway thanks for your suggestion.
|
|
|
|
|
i'd catch the donwloadcomplete event in unit-test and setting a flag (complete=true).
you can start the test then as follows:
<br />
[Test]<br />
public void TestDownload()<br />
{<br />
Downloader.DownloadReady += ...
Downloader.StartDownload(path)<br />
<br />
while (!complete)<br />
Application.DoEvents();<br />
}<br />
|
|
|
|
|
WOW ! That's great. Thanks for pointing this out
|
|
|
|
|
Calling Application.DoEvents is bad practice. It often results in unexpected results, so I would really advice against it.
If you can get a handle to the thread I'd use its Join method. If this isn't the case, you can use an AutoResetEvent to signal from one thread to the other. You can read more about it here[^].
Standards are great! Everybody should have one!
|
|
|
|
|
Another simple way is to use Thread.Join() method.....
Muhammad Talha
|
|
|
|
|
The way that I have implemented many solutions for this is to use a ManualResetEvent to pause the thread. Then when the work is complete in the second thread, set the ManualResetEvent allowing the first thread to continue.
Phil
|
|
|
|
|
Hi,
I'm sitting with a weird problem.
I created an application in C# 2005 Express. It has 3 timer controls in it.
The first timer runs as a clock (system clock) and once this timer reaches a specific time during the day it runs its procedure (this works fine)
The 2nd timer has its Interval set to 10min. So every 10 minutes it needs to run its procedure.(doesn't do it)
The 3rd timer has its Interval set to 10Sec. So every 10 second it needs to run its two procedures (doesn't do it either);
Now when i run this app in debug mode everything works perfect. Breakpoints are being reached all the time, I don't see any problems. But once i publish the app and install it on a users machine it doesn't always run the procedures
As u probably realized is that this application is an auto update app which auto updates data (retrieve data from webservice then update the local SQL database)
Any help would be greatly appreciated. I need to get this working by midday tomorrow.
Any other suggestions would be great.
Thanks
|
|
|
|