Data To Server

S

Simon Pulo

Hello again,
I'm having problems with sending data to the server, this is the code i am
using

int index = 0;

while (index < b64String.Length)
{
int size = Math.Min(b64String.Length - index, 77);
index += size;
dts = b64String.Substring(index, size);
Data = dts + CRLF;
szData = Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
}

When i run it i get the following error

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred
in mscorlib.dll

Additional information: Index and length must refer to a location within the
string.

Pointing to the line: dts = b64String.Substring(index, size);

anyone got any idea's?
 
J

Jani Järvinen [MVP]

Simon,
I'm having problems with sending data to the server, this is the code i am
using:

int size = Math.Min(b64String.Length - index, 77);
index += size;
dts = b64String.Substring(index, size);

When i run it i get the following error:
Additional information: Index and length must refer to a location within
the string.

Most probably you've already figures out the solution during the weekend,
but I'm replying nonetheless now that I got back to my PC. The error happens
because you are incrementing the "index" variable before you should. That
is, try arranging the lines like this:

------------
int size = Math.Min(b64String.Length - index, 77);
dts = b64String.Substring(index, size);
index += size;
------------

That should work. Hope this helps.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top