|
Thanks for the help However...when I try using the code I get this error:
'mrmanga.ZipHolder.ZipHolder()' is inaccessible due to its protection level
Any idea?
--- edit ---
Also, when i try making ZipHolder() public, I get this:
An unhandled exception of type 'System.StackOverflowException' occurred in mrmanga.exe
|
|
|
|
|
Hi,
Sorry I wasn't clear, and I think it lost some of the information I added in a tag.
Ok.
To open the zip file
ZipHolder.Instance.Open("zipfile.zip");
To access the instance of ZipArchive (held inside the ZipHolder)
public void ShowImage(int theNum)
{
AbstractFile imageFile = ZipHolder.Instance.Zip.GetFile(zipFiles[num]);
if (imageFile.Exists)
{
using( Stream stImage = imageFile.OpenRead() )
{
pbMain.Image = Image.FromStream(stImage);
}
}
}
etc..
Gary
|
|
|
|
|
! Ahh worked like a charm! Took me a little modding (had to throw in a static, and change string to abstractfile) but sure enough, it works I can't thank you enough. Thanks ^^
|
|
|
|
|
I write these every day and still forgot the static in the example
Gary
|
|
|
|
|
Can anybody please help? Developed code WinXP SP2, works as expected when built as Debug or Release. Distribute to WinME partition - if 'filename' exists works, if it doesn't the new file is written to C:\windows\temporary internet files\ . Doesn't seem quite right! Significant Code (condensed!) is: -
// filename is path\newbak.cfg
string oldfile = filename;
oldfile = oldfile.Replace(".cfg",".old");
if (File.Exists(oldfile)) File.Delete(oldfile);
if (File.Exists(filename)) File.Move(filename,oldfile);
FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter swr = new StreamWriter(stream);
swr.WriteLine(this.Title); // etcetera........
swr.Close();
stream.Close();
66 year young - or old and past it whichever! c# newbie.
|
|
|
|
|
What is the working directory of the application? I.e., is this an executable that is deployed using touchless deployment (launched from a browser)? By default, the application - like every other file you view in a browser - is downloaded to the temp. Internet files folder and executed. The working directory would be that directory unless you override it.
Also, a better way to deal with writing to streams is using the using block. This ensures that even if an exception occurs, the file handle (the native handle) is closed and you don't run into problems. Like so:
using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write))
{
using (StreamWriter swr = new StreamWriter(stream))
{
swr.WriteLine(this.Title);
swr.Flush();
}
} This will dispose of the stream, which also closes the file handle. I don't remember if it is flushed in Dispose or not, but it doesn't hurt to call Flush anyway to make sure your writes are committed and not droped before the file handle is closed (loss of data).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks Heath - I hadn't met the 'in code' use of 'using', and will (later) amend my code - your comments are 100% accepted. However, I believe that there is an underlying problem. The program is a Windows Executable, and is installed to c:\newbak in windows ME. I run the program from the desktop shortcut set up (correctly) by the install. The code used to invoke the file write is in only one place:
string workdir = System.IO.Directory.GetCurrentDirectory();
tempcfg.tofile(workdir + "\\newbak.cfg");
I changed to use the explicit path when I got my problem - in .net debug, it works perfectly with the default! I accept that there is a better way to code the file write, but the .net calls were lifted from a SAMS VB .net 2003, and I assume that an explicit streamwriter close would include a flush. That the code behaves strangely:
If c:\newbak\newbak.cfg exists, 'renames' it to .old and then creates a new c:\newbak\newbak.cfg (as expected).
If c:\newbak\newbak.cfg DOESN'T exist, it writes c:\windows\temporary internet files\newbak.cfg.
The only differencein the code flow is that the 'rename' code is not executed in the second case.
My 40 years in IT, and my not having gainful employment at present, means I will continue to convince myself the .NET is better than Borland C++ Builder (garlic out now!), and re-run with messageboxes at strategic locations. Of course, I have PROBABLY done something stupid and if so I will own up. Any other advice gratefully received.
Thanks again
Graham
66 year young - or old and past it whichever! c# newbie.
|
|
|
|
|
The actual code would be helpful. Many times people post "similar" code that doesn't contain the actual problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks again - will email the code.
Further info:
1) Windows ME - With MessageBox displays - everything works, without them NO FILES WRITTEN anywhere at all at all! Using 'using' construct had no effect.
2) Deploy to Windows XP test partition - everything works!
Graham
66 year young - or old and past it whichever! c# newbie.
|
|
|
|
|
Further to the discussion with Heath, I have done a lot of extra testing, in principle looking for the minimum set of code that still upsets Windows ME. Since the code is developed in Windows XP, this obviosly involves a lot of reboots! The tests were inconclusive until ME advised me that the last several executions had resulted in the OS going into standbye - did I want this to stop?
With Power Options all off - everything works perfectly!!!
Seems that anybody distibuting to Win98/ME may need a health warning about Power Options?
66 year young - or old and past it whichever! c# newbie.
|
|
|
|
|
Using: VS 2003
How do I bind a vScrollBar to a datagrid so the grid moves vertically when the user slides the control/pad. My datagrid gives the hScrollBar by default. Control docking is done through VS
this.dataGrid.Controls.Add(vScrollBar1); this.vScrollBar1.Visible = true;
this.vScrollBar1.Show();
Thanks
Steve
|
|
|
|
|
Hello,
i've setup a simple chat program using the Socket class with Async send and receive. All work good but i cant find an event that from the Server application warn it that a socket connection with a client is disconnected from the client itself. I can send a "disconnection" message from the client before closing the application but it doesnt work if for some kind of problem the program terminates (networking problems, crash of the computer, etc).
Thanks in advance for any ideas
Gian
|
|
|
|
|
There is no event that's fired when the client crashes. There is no way for the server to know that the client crashed unless it attempts to send something to the client. Only then will the server be able to detect the send failure and raise it's own event to the remaining clients.
A way around this might be to implement a "heartbeat". Either the server would send out a "ping" to all of the clients requiring the clients to send the data in the ping back to the server or the clients would have to send "heartbeat" packets to the server. Either method would have to be on a set time, say once every 10 seconds. If the heartbeat or ping is no longer detected after a specified timeout value, say 30 seconds, then the server can assume that the client is no longer functional and raise its own event that notifies the remaining clients.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
i have make an windows services in c# ... the code is running ok ... there is no error in that .... in my code i am trying to hook the keyboard and save all the pressed keys in a txt file ... on services start it has to make a txt file and when the service stop it has to make one more txt file but on start it is not meaking any file but on stop it is meaking a file ... i don't know what is the problem with it ... i can send you my code if you can solve my this problem ... ok seea byee
waiting for a flash reply ...
Maz.
Mazhar Hussain
|
|
|
|
|
You might want to double check the code that is opening and writing that first file. Maybe your handling and burying an expection that is being returned when the file is opened. You might want to check the Event Log for any errors and you might want to modifiy your code to report any handled exceptions to the Event Log to make it easier to debug your service.
You can check out Debugging Windows Service Applications[^] on MSDN for more information.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can you pls send code to me. I don't say I will solve the problem but I want to give it a try
Sandeep Naik
sandeep_n75@hotmail.com
|
|
|
|
|
hi
i add you on my msn messenger ... and i am waiting for you to come online and have a chat with you on it ...
Maz
Mazhar Hussain
|
|
|
|
|
I'm making a program to schedule my programs and to shut down my computer in a choosen time but this way my processor is 100 percent, logicaly. How can i change this.
while (!(System.DateTime.Now.Equals(shut.getDateTime())))
{
}
this.Computer_Shutdown();
Please help me. Thank you. 
|
|
|
|
|
Add a Thread.Sleep(1) into your while loop and cpu usage will drop
Otherwise you could use a timer to periodically process the following:
if (System.DateTime.Now.Equals(shut.getDateTime()))
this.Computer_Shutdown();
www.troschuetz.de
|
|
|
|
|
Using such a busy wait is _really_ bad style.
I'd suggest the following:
Create a new timer and set it's interval to the amount of milliseconds from now to the desired shutdown time:
Timer shutTimer = new Timer();
shutTimer.Tick += new EventHandler(shutTimer_Tick);
TimeSpan waitDuration = shut.GetDateTime().Subtract(DateTime.Now);
shutTimer.Interval = (int)waitDuration.TotalMilliseconds;
shutTimer.Start();
[...].private void shutTimer_Tick(object sender, EventArgs e)
{
this.Computer_Shutdown();
}
Regards,
mav
|
|
|
|
|
But I can't use a timer because I'm using a thread to do this, i tried and did not work. The idea is great. Thanks. 
|
|
|
|
|
That's why there are several different types of timers in .NET.
If you can't use a System.Windows.Forms.Timer (because you don't have a GUI) then a System.Timers.Timer should work fine. The events differ a little, but the concept stays the same: Calculate how long until the desired shutdown time and wind up the timer...
Regards,
mav
|
|
|
|
|
I want to create a single setup project that:
1. Upgrades to Windows Installer 2.0
2. installs a C# setup project MSI
Do u think i would be needing to upgrade through the redistributable package of SP2 or is there another way?
I have previously used a similar setup project(available on the microsoft website) that installs a .NET Framework Application and Dotnetfx.exe (the redistributable package of dotnet framework + upgrades to Windows Installer 2.0). This time i dont need the dotnetframework, only need to upgrade the Windows installer to 2.0, so that my MSI runs (it requires Windows Istaller 2.0)
Please help me out here.
Thanks.
|
|
|
|
|
If it's a C# project, the user must have the .NET Framework. All versions of the framework, IIRC, use Windows Installer 2.0. If the user already has the framework, they should already have Windows Installer 2.0.
If you're using VS.NET to create the MSI, in Project Properties you can set the Bootstrapper to 'Windows Installer Bootstrapper'. This copies InstMsiA.exe and InstMsiW.exe (the Windows Installer redistributables) and a Setup.exe to the output folder, and generates a Setup.ini which tells Setup.exe to launch your MSI. If you want to ship that as a single EXE, you should look into something like IExpress[^].
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi,
Is there a simple method to place two single quotes anywhere there is a single quote so that single quotes can be inserted into a database? Currently I have been searching through each string (textbox, or what ever it may be) and manually (looking at each character in the string) replacing the single quote with two single quotes. I have also tried the Replace function but that does not appear to change the single quotes. If any one has experinced this please pass on your knowledge or point me in the right direction.
Thanks
Joe
|
|
|
|