1
I have it:
private List<string> _listaCommiter()
{
string s = string.Empty;
string _start = ConfigurationSettings.AppSettings["dir_inicio"];
List<string> lista = new List<string>();
List<string> tes = new List<string>();
string path = ConfigurationSettings.AppSettings["Caminho_Commiter"];
string[] arquivos = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
string texto = string.Empty;
foreach (var item in arquivos)
{
s = Path.GetFileNameWithoutExtension(item);
int _int = item.ToString().IndexOf(_start);
texto = item.ToString().Substring(_int, item.Length);
if (!item.Contains("TSNMVC"))
lista.Add(s);
}
return lista;
}
The moment I mount the text variable inside the foreach, it gives me this error:
Message=The index and length should refer to a location within the character string. Name of parameter: length
Below the whole error message
System.Argued tofrangeexception was unhandled Hresult=-2146233086 Message=The index and length should refer to a location within the string. Parameter name: length Source=mscorlib
Paramname=length Stacktrace: in System.String.Substring(Int32 startIndex, Int32 length) in Creationextraindo_zip.Form1. _listCommitter() in c: Projects_amil Creationextraindo_zip Creationextraindo_zip Form1.Cs:line 211 in Creatureextraindo_zip.Form1.button1_Click(Object Sender, Eventargs e) in c: Projects_amil Creationextraindo_zip Creationextraindo_zip Form1.Cs:line 240 in System.Windows.Forms.Control.Onclick(Eventargs and) in System.Windows.Forms.Button.Onclick(Eventargs and) in System.Windows.Forms.Button.Onmouseup(Mouseeventargs mevent) in System.Windows.Forms.Control.Wmmouseup(Message& m, Mousebuttons button, Int32 clicks) in System.Windows.Forms.Control.Wndproc(Message& m) in System.Windows.Forms.ButtonBase.Wndproc(Message& m) in System.Windows.Forms.Button.Wndproc(Message& m) in System.Windows.Forms.Control.Controlnativewindow.Onmessage(Message& m) in System.Windows.Forms.Control.Controlnativewindow.Wndproc(Message& m) in System.Windows.Forms.NativeWindow.Debuggablecallback(Intptr hwnd, Int32 msg, Intptr wparam, Intptr lparam) in System.Windows.Forms.UnsafeNativeMethods.Dispatchmessagew(MSG& msg) em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 Reason, Int32 pvLoopData) in System.Windows.Forms.Application.Threadcontext.Runmessageloopinner(Int32 Reason, Applicationcontext context) in System.Windows.Forms.Application.Threadcontext.Runmessageloop(Int32 Reason, Applicationcontext context) in System.Windows.Forms.Application.Run(Form mainForm) in Creationextraindo_zip.Program.Main() in c: Projects_amil Creationextraindo_zip Creationextraindo_zip Program.Cs:line 19 in System.AppDomain. _nExecuteAssembly(Runtimeassembly Assembly, String[] args) in System.AppDomain.Executeassembly(String assemblyFile, Evidence assemblySecurity, String[] args) in Microsoft.VisualStudio.Hostingprocess.HostProc.Runusersassembly() in System.Threading.Threadhelper.Threadstart_context(Object state) in System.Threading.Executioncontext.Runinternal(Executioncontext executionContext, Contextcallback callback, Object state, Boolean preserverveSyncCtx) in System.Threading.Executioncontext.Run(Executioncontext executionContext, Contextcallback callback, Object state, Boolean preserverveSyncCtx) in System.Threading.Executioncontext.Run(Executioncontext executionContext, Contextcallback callback, Object state) in System.Threading.Threadhelper.Threadstart() Innerexception:
In debug, what is inside
_int
anditem
before the error?– Leonel Sanches da Silva
@Ciganomorrisonmendez, _int has the position in which I want to reassemble the new string, which in the first case is 13. Item is an array with the names of the files I want to handle This is correct.
– pnet
Are you sure? If you were, you wouldn’t be making a mistake. Put a breakpoint in
texto = item.ToString().Substring(_int, item.Length);
and check item by item.– Leonel Sanches da Silva
When the text arrives = ... I can’t walk anymore, because that’s where the error occurs, but in item yes, it is correct as I said above.
– pnet
There is a tab in Visual Studio called
Watch 1
. Play the line content there and see what happens.– Leonel Sanches da Silva
This is the first step of item:
C:\Teste_Zip\web\ace\ace003c.asp
– pnet
above this line text = .... , is giving this in watch1:
texto = item.ToString().Substring(_int, item.Length); 'item.ToString().Substring(_int, item.Length)' threw an exception of type 'System.ArgumentOutOfRangeException' string
– pnet
I made the hand and gave the same mistake. I did so:
string s1 = @"C:\Teste_Zip\web\ace\ace003c.asp";
 int _n = s1.IndexOf(_start);
 string s2 = s1.Substring(_n, s1.Length);
– pnet
On the bottom lines, put
_int
in a anditem
in another. See the result.– Leonel Sanches da Silva
@Ciganomorrisonmendez, I don’t understand what you mean by "bass lines"
– pnet
It worked that way:
texto = item.ToString().Substring(_int, item.Length-_int);
.– pnet