Hi,
I wrote simple program to get the .c and .h files in a folder and number of
lines they contain. It works; but when i choose the 'c:\' folder, i get an
Argument Exception.
when i choose another driver or folder, there is no error. what could be the
reason? if the reason is hidden system files which is being used by System,
is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)"
block);
for (int i = 0; i < files.Length; i++)
{
if ((files[i].Substring(files[i].Length - 2) == ".c") ||
(files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") ||
(files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
}
} 6 6365
Hi,
What does the message of ArgumentException says? , where it's thrown?
IIRC this exception is thrown only when an argument is invalid, get the
line that is throwning it wrapped in a try/catch and see what values the
parameters have.
If unable to solve it just post the above answer here.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl... Hi, I wrote simple program to get the .c and .h files in a folder and number of lines they contain. It works; but when i choose the 'c:\' folder, i get an Argument Exception. when i choose another driver or folder, there is no error. what could be the reason? if the reason is hidden system files which is being used by System, is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)" block);
for (int i = 0; i < files.Length; i++) {
if ((files[i].Substring(files[i].Length - 2) == ".c") || (files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") || (files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
}
}
I think the brief exception code is;
-COMPlusExceptionCode -532459699
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>, haber
iletisinde şunları yazdı:uZ*************@TK2MSFTNGP02.phx.gbl... Hi,
What does the message of ArgumentException says? , where it's thrown?
IIRC this exception is thrown only when an argument is invalid, get the line that is throwning it wrapped in a try/catch and see what values the parameters have.
If unable to solve it just post the above answer here. -- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl... Hi, I wrote simple program to get the .c and .h files in a folder and number of lines they contain. It works; but when i choose the 'c:\' folder, i get an Argument Exception. when i choose another driver or folder, there is no error. what could be the reason? if the reason is hidden system files which is being used by System, is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)" block);
for (int i = 0; i < files.Length; i++) {
if ((files[i].Substring(files[i].Length - 2) == ".c") || (files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") || (files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
}
}
Hi,
In what line?
What about the InnerException? Post the Message of both here.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message
news:OF**************@TK2MSFTNGP04.phx.gbl... I think the brief exception code is; -COMPlusExceptionCode -532459699
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>, haber iletisinde şunları yazdı:uZ*************@TK2MSFTNGP02.phx.gbl... Hi,
What does the message of ArgumentException says? , where it's thrown?
IIRC this exception is thrown only when an argument is invalid, get the line that is throwning it wrapped in a try/catch and see what values the parameters have.
If unable to solve it just post the above answer here. -- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl... Hi, I wrote simple program to get the .c and .h files in a folder and number of lines they contain. It works; but when i choose the 'c:\' folder, i get an Argument Exception. when i choose another driver or folder, there is no error. what could be the reason? if the reason is hidden system files which is being used by System, is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)" block);
for (int i = 0; i < files.Length; i++) {
if ((files[i].Substring(files[i].Length - 2) == ".c") || (files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") || (files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
}
}
Hi,
Now I tried to run the program for 'C:\' folder after removing try-catch
block.
and I see the error at the last line.
if ((files[i].Substring(files[i].Length - 2) == ".c") ||
(files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") ||
(files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString(); >>>>>>
Here i get the error;
}
Exception Detail;
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the
size of the collection.\r\nParameter name: index"
Source="mscorlib"
ParamName="index"
StackTrace:
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.DataGridViewRowCollection.Sha redRow(Int32
rowIndex)
at System.Windows.Forms.DataGridViewRowCollection.get _Item(Int32
index)
at SatirSayaci.Form1.countbutton_Click(Object sender, EventArgs e) in
D:\code\csharp\SatirSayaci\SatirSayaci\Form1.cs:li ne 99
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SatirSayaci.Program.Main() in
D:\code\csharp\SatirSayaci\SatirSayaci\Program.cs: line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Hi,
What is the value of i ?
What about dataGridView1.Rows.Count ?
My bet is that dataGridView1.Rows.Count < i
is dataGridView1 a dataview?
What if you do
dataGridView1.Rows[ dataGridView1.Rows.Count -1 ].HeaderCell.Value =
i.ToString();
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl... Hi, Now I tried to run the program for 'C:\' folder after removing try-catch block. and I see the error at the last line.
if ((files[i].Substring(files[i].Length - 2) == ".c") || (files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") || (files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString(); >>>>>> Here i get the error;
} Exception Detail;
System.ArgumentOutOfRangeException was unhandled Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index" Source="mscorlib" ParamName="index" StackTrace: at System.Collections.ArrayList.get_Item(Int32 index) at System.Windows.Forms.DataGridViewRowCollection.Sha redRow(Int32 rowIndex) at System.Windows.Forms.DataGridViewRowCollection.get _Item(Int32 index) at SatirSayaci.Form1.countbutton_Click(Object sender, EventArgs e) in D:\code\csharp\SatirSayaci\SatirSayaci\Form1.cs:li ne 99 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at SatirSayaci.Program.Main() in D:\code\csharp\SatirSayaci\SatirSayaci\Program.cs: line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context( Object state) at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
i changed it as,
dataGridView1.Rows[dataGridView1.Rows.Count - 2].HeaderCell.Value =
(dataGridView1.Rows.Count - 1).ToString();
and the problem was solved.
thank you.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>, haber
iletisinde şunları yazdı:Oq**************@TK2MSFTNGP05.phx.gbl... Hi,
What is the value of i ? What about dataGridView1.Rows.Count ?
My bet is that dataGridView1.Rows.Count < i
is dataGridView1 a dataview?
What if you do
dataGridView1.Rows[ dataGridView1.Rows.Count -1 ].HeaderCell.Value = i.ToString(); -- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Sirin Azazi" <si****@tedasnet.gov.tr> wrote in message news:%2****************@TK2MSFTNGP03.phx.gbl... Hi, Now I tried to run the program for 'C:\' folder after removing try-catch block. and I see the error at the last line.
if ((files[i].Substring(files[i].Length - 2) == ".c") || (files[i].Substring(files[i].Length - 2) == ".C")
|| (files[i].Substring(files[i].Length - 2) == ".h") || (files[i].Substring(files[i].Length - 2) == ".H"))
{
FileStream fs = new FileStream(files[i],FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files[i] = files[i].Substring(fpath.Length);
if (files[i].StartsWith("\\")) files[i] = files[i].Substring(1);
newrow = new string[]{ files[i],(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows[i].HeaderCell.Value = i.ToString(); >>>>>> Here i get the error;
} Exception Detail;
System.ArgumentOutOfRangeException was unhandled Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index" Source="mscorlib" ParamName="index" StackTrace: at System.Collections.ArrayList.get_Item(Int32 index) at System.Windows.Forms.DataGridViewRowCollection.Sha redRow(Int32 rowIndex) at System.Windows.Forms.DataGridViewRowCollection.get _Item(Int32 index) at SatirSayaci.Form1.countbutton_Click(Object sender, EventArgs e) in D:\code\csharp\SatirSayaci\SatirSayaci\Form1.cs:li ne 99 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at SatirSayaci.Program.Main() in D:\code\csharp\SatirSayaci\SatirSayaci\Program.cs: line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context( Object state) at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kelly |
last post by:
hi all,
it's me again. i'm using ASP.NET Web Application, using a "File Field"component under HTML tab and i do a right click on the component and select "Run As Server Control". This was done...
|
by: strutsng |
last post by:
<input type="file"> only allows the user to browse for files.
How about "browse for folder" dialog? Can html/javascript do that? I
couldn't find any syntax for that. If not, please advise what...
|
by: Phil Stanton |
last post by:
Can anyone let me have the code for opening the open file dialog box and
getting either a file or folder name as the output.
I suspect it will look like
Function GetPathOrFile(InputPath as...
|
by: bcanavan |
last post by:
I'm trying to link a remote client Access app (through the internet) to
an mdb in a web folder on my web server. The idea is to give users
readOnly access to the web folder mdb, which itself links...
|
by: Salad |
last post by:
I designed a small app and I wanted to do a BrowseFolder (see
http://www.mvps.org/access/api/api0002.htm), basically do a file open
diaglog and select a directory/folder. The problem is that you...
|
by: Dan |
last post by:
I am working on a C# ASP.NET project where I need to allow the user to
browse to a folder. The only way I see how to do this is use <input
type=file>. But this makes the user select a file and...
|
by: Nick 'The Database Guy' |
last post by:
Hi All,
I want to browse to a particular folder, not a particular file.
The reason for this is that I have a utility that asks people to browse
to a certain file, and I want them to be able to...
|
by: rdemyan |
last post by:
I'm using code from the following web page to open the API Browse Folder
dialog
http://www.mvps.org/access/api/api0002.htm
It all works fine. But if the dialog box is open and the user closes...
|
by: =?Utf-8?B?TXVydWdlc2FuUA==?= |
last post by:
I am trying to browse folders through the following piece of code.
Please let me know if there is any kind of setting to get this working.
I want this to appear at the client side, but it should...
|
by: evenlater |
last post by:
I have an Access application on a terminal server. Sometimes my users
need to export reports to pdf, rtf or xls files and save them to their
own client device hard drives.
They can do that right...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |