|
Thank you! Works like a charm. Now as I see it it seems logical.
|
|
|
|
|
Hi,
Iam trying to open a word document using filestream and thereby put the data in byte array by reading the filestream.
Now, i want to write back the byte stream to a file like doc file, would there be any complexities by doing this?
If the document has some images can it be written back to a file?
code is as follows:
//for reading
FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Read);
long len;
len = fileStream.Length;
Byte[] fileAsByte = new Byte[len];
fileStream.Read(fileAsByte, 0, fileAsByte.Length);
same logic for writing too
Thanks,
gauthee
|
|
|
|
|
Hi,
you can read all bytes of all files you can access.
and you can write these bytes again to any location you can access.
Since .NET 2.0 you can do it with File.ReadAllBytes and File.WriteAllBytes,
you don't need streams for that.
Don't really know what good it all will do for you tho. You probably will
not be able to understand the bytes, nor change them in any way that
results in a valid new document. And you can't just convert a document
by changing its file extension, if that were what you hope for.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi All,
I have got a problem in events. I have a treeview Before_Select event and one is Panel_leave event
so when i m on panel and i click a treenode the Panel_leave is executed but Before_Select doesn't execute .But if i make a break point in Panel_leave it works and if i remove break points it doesn't work.
Please help in solving this problem , I think i need thread Synchronization , but i don't know how to do it.
Thanx.
Praveen Sharma
|
|
|
|
|
Hi,
the events go to the active message pump, that is the GUI trhead of the
currently active window (which normally means: the main thread for all windows).
So Panel_leave and Before_Select normally get handled by the same thread,
that will not be the problem.
Are you sure Before_Select does not fire? How did you figure that?
Best way is: add log statements such as log("begin of Before_Select");
and provide a log method in every interested class, e.g.
public static void log(string s) {
s=DateTime.Now.ToString("hh:mm:ss.fff")+" "+s;
Console.WriteLine(s);
}
If however you try to manipulate some controls from inside another thread,
then you must use Control.InvokeRequired property and Control.Invoke() method;
if not, all kinds of strange things may and will happen.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi!
I have something like this:
public class MyApp: System.Windows.Application
{
public MyApp()
{
m_Window = new Window();
}
Window m_Window;
}
and it gets instantiated from:
class Program
{
[STAThread]
static void Main()
{
MyApp app = new MyApp();
app.Run();
}
}
Every time someone says m_Window.Close() the whole application gets terminated ( = also 'app' gets terminated).
But that is not what I want, I want only to close m_Window ( = 'app' should keep running).
So, where did I go wrong?
Thanks,
Mario M.
|
|
|
|
|
It Works when I derive MyApp from System.Windows.Window but it looks quite ugly:
public class MyApp : Window
{
public MyApp()
{
this.Visibility = Visibility.Hidden;
m_Window = new Window();
}
Window m_Window;
}
class Program
{
[STAThread]
static void Main()
{
Application app = new Application();
MyApp win = new MyApp();
app.Run();
}
}
|
|
|
|
|
m_Window.Close() is different than Visibility.Hidden now isn't it.
In the first case, yes, the application will terminate because the form has been closed, thus terminating the message loop. In the second case the window is not closed, just hidden, so the message loop continues and the application does not terminate.
only two letters away from being an asset
|
|
|
|
|
So what's your point?
In the first case I derived it from 'Application' and in the second I derived it from 'Window'.
But I don't want to derive it from 'Window' because it is no window.
|
|
|
|
|
The point is, learn the difference between window.close and window.hidden
only two letters away from being an asset
|
|
|
|
|
How about looking at the two DIFFERENT code samples I posted?
In the first snipped I create an App that has a window as member (only one window). When the window gets closed also the app terminates.
And in the second sample I create a hidden window that has an additional window as member (two windows). I don't say: m_window.hidden! I hide the parent!
But I think creating a hidden window just to make sure that the class itself survives when one of its members gets closed is quite ugly.
So, please have a look at the code first, before you start getting wise!
Mario M.
|
|
|
|
|
MarioMARTIN wrote: before you start getting wise!
Too late, already am.
only two letters away from being an asset
|
|
|
|
|
Hi,
a normal window app has an Application.Run(new Form1()); in its static main method.
The Run method will show the Form1 instance (and run a message loop to do that),
and it will return when the form gets closed or Application.Exit() gets called.
as an alternative you can call Application.Run(); without arguments;
that one will start a message pump and return when Application.Exit() gets called.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
"as an alternative you can call Application.Run(); without arguments;"
yeah thanks, but I think taht is what I showed already in my first posting.
Maybe I should try it verbally:
1.) I want an application that instantiates a class
2.) This class should open a window
3.) When the window gets closed the class should stay 'alive' (and therefore also the application must not get terminated)
Mario M.
|
|
|
|
|
Hi,
one way of doing that is:
- create a Windows app with a main form
- hide the main form (it initially might have served as a splash screen)
- create another window/form/whatever, maybe inside the main form's Load event
- do whatever you want with that window/form/whatever, closing it does not
affect the (invisible) mainform, hence the app continues (doing what I might ask).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Forget it, I'll take the "derive from Window" approach
Thanks,
Mario M.
|
|
|
|
|
Hello,
MarioMARTIN wrote: Forget it,
No! why?
It's interesting and might help somebody else if cleared up!
MarioMARTIN wrote: I'll take the "derive from Window" approach
Which, is what Luc pointed out, very well explaint, here![^]
He got my '5' for that!
All the best,
Martin
|
|
|
|
|
Hi!
"Which, is what Luc pointed out, very well explaint, here!"
And what I already posted here
Ciao
Mario M.
|
|
|
|
|
Hello,
MarioMARTIN wrote: And what I already posted here
I know! And I think Luc did also read your post, but wanted to clear it up for you and others!
All the best,
Martin
|
|
|
|
|
Problem solved:
[STAThread]
static void Main()
{
Application app = new Application();
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
MyApp win = new MyApp();
app.Run();
}
class MyApp
{
public MyApp()
{
m_Win = new Window();
m_Win.ShowDialog();
}
Window m_Win;
}
}
|
|
|
|
|
i can't connect sql 2000 for visual studio 2005 verssion.
|
|
|
|
|
What error do you get?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I doubt he has any code. Look at his previous posts.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
leckey wrote: Look at his previous posts.
4 posts labeled "C#" I just about blew my brains out.
Again...
Location India
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hello,
Justin Perez wrote: 4 posts labeled "C#" I just about blew my brains out.
Totally agree with you!
Justin Perez wrote: Again...
Location India
I don't feel comfortable with this kind of statements, and it's not constructive as well!
All the best,
Martin
|
|
|
|