|
Hi
I am having a code for 2 functions one is to Extract the file from a zip file. Another one is to read the Extracted file n parse it.
While Execution the application I am getting an exception The File(Extracted file) being used by some other application and its exiting by showing the line number "StreamReader sr = File.OpenText(FILE_NAME);".
But If I am debugging the application ..the results r perfectly fine.
Can Any one please explain this.
I am attaching the functions here
public static void ExtractZIPFile()
{
sbyte[] buf = new sbyte[1024];
int len;
java.io.FileInputStream fis = new java.io.FileInputStream(@"C:\TEMP\POWER_PRODUCTS.ZIP");
java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(fis);
java.util.zip.ZipEntry ze;
ze = zis.getNextEntry();
java.io.FileOutputStream fos = new java.io.FileOutputStream(FILE_NAME);
while ((len = zis.read(buf)) >= 0)
{
fos.write(buf, 0, len);
}
zis.close();
fis.close();
FileProcessing();
}
public static void FileProcessing()
{
if (!File.Exists(FILE_NAME))
{
Console.WriteLine("{0} does not exist.", FILE_NAME);
return;
}
CreatePPTable();
StreamReader sr = File.OpenText(FILE_NAME);
String input="";
while ((input= sr.ReadLine())!=null)
{
String []strs = input.Split(';');
#region Add a row
DataRow drNew = dsPProducts.Tables[0].NewRow
drNew["PASS2_AVAIL_CD"] = strs[1];
...
drNew["PASS2_AVAIL_CD"] = strs[122];
dsPProducts.Tables[0].Rows.Add(drNew);
#endregion end of adding a row
Console.WriteLine(input);
}
sr.Close();
File.Delete(FILE_NAME);
}
|
|
|
|
|
Looks like you forgot to close fos in the following snippet.
dvsr wrote: java.io.FileOutputStream fos = new java.io.FileOutputStream(FILE_NAME);
while ((len = zis.read(buf)) >= 0)
{
fos.write(buf, 0, len);
}
When debugging, the GC must have run and closed it for you. That would explain the debug/release behavior.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Sinthil,
Thanks for ur Help....
Once again its proved How dumb i am..
Thank you once again.
Subbu
|
|
|
|
|
Hi everybody.
I'm developing a program which has a combobox with all client names but as client name is not the primary key, or better: unique, on the database, some itens on the combo box are repeated, so this way there is more than one person with the same name.
In order to solve that I'd like to know if it is possible to associate another value (preferable an unique ID which would be loaded from the database) for each item on the combo box, but in a way that the program user would see only the name on the combo, not this unique ID, which would be used by the program.
If my explanation was not clear:
- I'd like to have this user view on the combo box:
John Wallace
Marck Keen
Isaac May
John Wallace
The way it is right now (no associated values) I can't do a query that would retrieve me only one row, because using "select * from table where name = ' + combo.SelectedItem.toString() + "'"; it would retrieve me 2 rows if, for example, I select John Wallace which has 2 occurences on the same combo.
So, behind the scenes, I'd like to retrieve the unique id from the selected item. So the program would have that:
John Wallace 344072407
Marck Keen 40947047
Isaac May 483609
John Wallace 20648
Thus, I can make a different selection based on the name, like:
"select * from table where uniqueID = ' + combo.SelectedItem."somethingThatWouldRetrieveMeTheUniqueID" + "'";
Thank you !
|
|
|
|
|
You could create a class like:
public class ComboEntry {
public string Name;
public int Id;
public override string ToString() {
return Name;
}
}
and put instances of it into the ComboBox. The ComboBox will call the ToString method to determine what text should be shown and when you access the SelectedItem property you can just cast back to ComboEntry and get the Id.
|
|
|
|
|
It worked the way I wished.
Thank you.
|
|
|
|
|
Set the DataSource of the Combo Box
and set display member as name
and set value member as id.
now u can get the id by --
int i=combobox.SelectedValue;
|
|
|
|
|
Is there possible to make a text box control skip interpreting certain keys without inheriting the class?
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Excluing native interop I don't think that there is a way.
Are you unable or just don't want to inherit from the TextBox? If you're unable, can you give us some more information on your situation?
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
The ideea is to make a class that recives\intercept key messages from a TextBox, process them and if necesary block the respective key from being processed by the TextBox.
The ideea of inheriting is not so great because this class should work with all kind of other control (richTextBox, comboBox, etc...)
Thank you!
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Yeah - subscribe to the KeyPress event. This event passes a KeyPressEventArgs which has a boolean Handled field. Setting this to true stops the message being passed on to the text box handler, so you can do your processing in this event.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for your answer, but I allready know this. The problem is that in a TextBox if you press for exemple the VK_LEFT the cursor moves to left if is a character there.
I want to intercept this type of key before processing and decide if it mut be processed or not. (KeyPress event work's only for char key's if I am not mistaking)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Ah, ok.
Well, you can intercept virtual keys using the KeyDown event which is fired prior to the KeyPress event.
eg. To disable the left cursor key:
<br />
private void textBox1_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.Left)<br />
{<br />
e.Handled = true;<br />
}<br />
}<br />
You may still need to worry about mouse selection depending upon what you are doing...
Regards,
Rob Philpott.
|
|
|
|
|
Hi all!
I got a Windows Forms application where an event is fired from a secondary thread. When this event is fired, I call
this.BeginInvoke(new MethodInvoker(someMenuItem.PerformClick)); to simulate a menu item click.
This works fine, but when the event handler for someMenuItem pops up a modal dialog, this dialog appears more than once if the event re-fires before the first dialog is closed.
So I tried encapsulating someMenuItem 's event handler code inside a lock(this) {} and now only a single modal dialog is shown at most.
So far, so good.
But if the event re-fires now, all these events are suspended as long as the lock() statement is active and executed in row afterwards.
Is there a way to change the behaviour so that the events are discarded instead of being stored?
Thanks in advance for any ideas,
mav
|
|
|
|
|
|
Jared, thanks for your comment!
Of course, you're right. That way I can block the second thread until the first call to the event handler is finished.
The dialog can still pop up twice in a row (when I click the menu item in the main app and afterwards the other thread fires the event), but I think I'll use this approach nevertheless.
Or do you have any further suggestions on how to really discard every other call?
Thanks,
mav
|
|
|
|
|
The only way I can think of is having a volatile bool variable that is set before Invoke and is reset after it. That way, you can simply return if the flag is set.
class XYZ
{
volatile bool isMessageBoxVisible = false;
void Func()
{
lock(this)
{
if (isMessageBoxVisible) return;
isMessageBoxVisible = true;
}
this.Invoke(...);
lock(this) { isMessageBoxVisible = false; }
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks!
That could be a way, but then it gets quite messy, because I allow the user to configure which menu item or toolbar button is pressed when a certain button on the external input device is clicked.
So I'd have to create a variable for each and every menu item/toolbar button...
I was looking for a behaviour like what you get when you use the mouse to click a menu item/tbb. A modal dialog can pop up, but then the UI of the main window is not accessable any more and thus the same menu item/tbb can't be pushed more than once. And the additional clicks aren't queued but discarded.
Something like
if (mainForm.IsIdle)
this.Invoke(... But just as I write this I got another idea:
I usually set the form's Cursor to Cursors.WaitCursor at the beginning of my menu/toolbar event handlers and reset it to Default in a finally block.
This information can be used to decide whether the main form is busy (executing an event handler) or not. I think I'll try it like this:
if (mainForm.Cursor == Cursors.Default)
this.Invoke(...
Thank you all for your help!
mav
|
|
|
|
|
i wrote a sales report, which works fine with my application if i include start date and end date in the database, {gndsale.dob} in {date.startdate} to {date.enddate}.
but if i change the report to pass Parameter Fields, {gndsale.dob} in {?Start Date} to {?End Date}
when i load the report first time it's okay i can see the correct parameters on the Page header and in Details, but if i load report 2nd time with different parameters , the page header is updated but the details not, some how i need to refresh crystalReportViewer1 after i pass parameters. ???
check this code
ReportDocument1.Load(RptPath.ToString());
crystalReportViewer1.RefreshReport();
crystalReportViewer1.ReportSource = reportDocument1;
paramFields = new ParameterFields ();
ParameterField crParamFld = new ParameterField();
ParameterDiscreteValue CrparamValue = new ParameterDiscreteValue();
paramFields = crystalReportViewer1.ParameterFieldInfo;
crParamFld = paramFields[0];
CrparamValue.Value = PassDT_Start;
crParamFld.CurrentValues.Add(CrparamValue);
ParameterField crParamFld_2 = new ParameterField();
ParameterDiscreteValue CrparamValue_2 = new ParameterDiscreteValue();
crParamFld_2 = paramFields[1];
CrparamValue_2.Value = PassDT_End;
crParamFld_2.CurrentValues.Add(CrparamValue_2);
crystalReportViewer1.ParameterFieldInfo = paramFields;
crystalReportViewer1.ReportSource = reportDocument1;
Or this code
reportDocument1.SetParameterValue("Start Date",PassDT_Start );
reportDocument1.SetParameterValue("End Date",PassDT_End );
crystalReportViewer1.RefreshReport();
crystalReportViewer1.ReportSource = reportDocument1;
|
|
|
|
|
Hello,
I’m programming an MDI application. My application contains a sizable child form and a fixed dialog form. The problem is that when I maximize the sizable form, the fixed dialog form is maximised too. I don’t know how to keep the fixed dialog form in its normal state while the sizable child form is maximized. Has any one a solution? Thanks.
|
|
|
|
|
Is the dialog form an MDI Child form? If so, you can't seperate the two. If one MDI Child is maximized, they're all maximized. There is no way to stop that from happening. The solution is to make the dialog form a normal form, not an MDI Child.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The Error:
Could not find file "\\myserver\share$\myfile.txt".
The Code:
File.Copy(@"\\myserver\share$\myfile.txt",@"c:\myfile.txt"), true);
The file is there. The premissions on the share$ is set to everyone. I can navigate to the file using the above quoted string. What am I missing?
|
|
|
|
|
|
Hi!
I guess the problem lies in the share itself.
If you enter "\\myserver\share$" in the address bar of a windows explorer, do you get a dialog asking for a user name and password?
If you can see the file in your explorer, does the program still throw the exception afterwards?
Or is the code executed from within a windows service process running under LocalSystem account?
mav
|
|
|
|
|
thank you for responding...
no.. no dialog box appears. Any lowly person in the company and open this share no problem.
And the code is being executed by ASPNET account
|
|
|
|