Hi everybody, I have write a program send and recieve a large file , now it can transfer a file size 1.5G but when I choose large file about 2G it fail and notify:
http://i1055.photobucket.com/albums/s505/vn_photo/Untitled-27_zpscf61b7a1.jpg

Here is Project:

http://www.mediafire.com/?p9b2xj2970d7cqb

Please read and help me, it code is short, no long, I need a help I'm nearing to send it for my teacher, I hope everyone will help me.

How you are transferring.... Tell me the which topic you are using Client --> Server, Remoting , Web Service ? if you are more clear then its easy to help you out

Thank verymuch for instruction, I have replace and change some variable int to long as you guide but it get two error here, please repaired it for me.

Click Here

namespace server
{
    public partial class Form1 : Form
    {
        public delegate void UpdateListBoxCallBack(string s);
        public delegate void UpdateLabelCallBack(string s);
        public delegate void Updatepgdstatus(long s, long p);
        private NetworkStream nwkStream = null;
        private Socket socketForClient = null;
        private TcpListener tcpListener = null;
        private Stream stmReader = null;
        private Stream stmWriter = null;
        private Thread t = null;

        public Form1()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            IPHostEntry ips = Dns.GetHostByName(Dns.GetHostName());
            ipServer.Text = ips.AddressList[0].ToString();
            label5.Text = null;
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            txtFileName.Clear();
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Title = "Choose file to send";
            fileDialog.Filter = "Text Files (*.txt)|*.txt|Word Documents" + "(*.doc)|*.doc|All Files (*.*)|*.*";
            fileDialog.Multiselect = true;
            fileDialog.ShowReadOnly = true;
            if (fileDialog.ShowDialog(this) == DialogResult.OK)
            {
                txtFileName.Text = fileDialog.FileName;
                lblMessage.Text = null;
            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(startSever));
            txtFileName.Clear();
            lblMessage.Text = "Server have start!";
            lblprogressbar.Text = "";
            progressbar.Value = 0;
        }

        private void startSever()
        {
            try
            {
                set1("Listening");
                IPEndPoint ip = new IPEndPoint(IPAddress.Parse(ipServer.Text), int.Parse(port.Text));
                tcpListener = new TcpListener(ip);
                tcpListener.Start();
                socketForClient = tcpListener.AcceptSocket();
                if (socketForClient.Connected)
                {
                    NetworkStream ns = new NetworkStream(socketForClient);
                    StreamReader sr = new StreamReader(ns);
                    StreamWriter sw = new StreamWriter(ns);
                    string filename = txtFileName.Text;
                    nwkStream = new NetworkStream(socketForClient);
                    stmReader = File.OpenRead(txtFileName.Text);
                    stmWriter = nwkStream;
                    FileInfo flInfo = new FileInfo(txtFileName.Text);
                    //int size = Convert.ToInt32(flInfo.Length);
                    long size = flInfo.Length;
                    byte[] buff = new byte[32 * 2048];
                    int len = 0;
                    long progress = 0;
                    set1("Starting");
                    sw.WriteLine(filename);
                    sw.Flush();
                    while ((len = stmReader.Read(buff, 0, 2048)) != 0)
                    {
                        progress += len;
                        set3(size, progress);
                        set(progress.ToString() + " Byte of " + size + " Byte");
                        stmWriter.Write(buff, 0, len);
                        stmWriter.Flush();
                    }
                    set1("File has sent succesfully!");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (socketForClient != null)
                {
                    socketForClient.Close();
                    nwkStream.Close();
                    stmWriter.Close();
                    stmReader.Close();
                    tcpListener.Stop();
                }
            }
        }

        void set1(string s)
        {
            if (InvokeRequired)
            {
                object[] pList = { s };
                lblMessage.BeginInvoke(new UpdateListBoxCallBack(OnUpdateLabel), pList);
            }
            else
            {
                OnUpdateLabel(s);
            }
        }

        private void OnUpdateLabel(String s)
        {
            lblMessage.Text = s;
        }

        void set(string s)
        {
            if (InvokeRequired)
            {
                object[] pList = { s };
                lblprogressbar.BeginInvoke(new UpdateListBoxCallBack(OnUpdateLabel1), pList);
            }
            else
            {
                OnUpdateLabel1(s);
            }
        }

        private void OnUpdateLabel1(String s)
        {
            lblprogressbar.Text = s;
        }

        void set3(long s, long p)
        {
            if (InvokeRequired)
            {
                object[] pList = { s, p };
                progressbar.BeginInvoke(new Updatepgdstatus(OnUpdatepgdstatus), pList);
            }
            else
            {
                OnUpdatepgdstatus(s, p);
            }
        }

        private void OnUpdatepgdstatus(long s, long p)
        {
            progressbar.Maximum = s;
            progressbar.Value = p;
        }

        private void send_Click(object sender, EventArgs e)
        {
            t.Start();
        }

        private void sukien2(object sender, EventArgs e)
        {
            port.Clear();
        }
        private void clearPort(object sender, EventArgs e)
        {
            port.Clear();
        }

        private void ClearFile(object sender, EventArgs e)
        {
            txtFileName.Clear();
        }

        private void disconnect(object sender, EventArgs e)
        {
            label5.Text = "Connect have drop!";
            socketForClient.Close();
            tcpListener.Stop();
        }

        private void exit(object sender, EventArgs e)
        {
            Close();
        }

        private void clearfilename(object sender, EventArgs e)
        {
            txtFileName.Clear();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }
    }
}

Lines 155 $ 156 use Convert.ToInt32

Hi a fix it as below.

private void OnUpdatepgdstatus(long s, long p)
{
    progressbar.Maximum = Convert.ToInt32(s);
    progressbar.Value = Convert.ToInt32(p);
}

So when I choose fie *iso about 2.5G it still fail ? if i replace to ToInt64 it not appropriate

Try using Convert.ToUInt32. Being unsigned you'll get a maximum of about 4 GB.

Ok I think I've got it now. Since the progress bar will only accept int anything over 2 GB will be too large. To accommodate larger files make the progressbar.maximum a fraction of the total size, maybe 1 tenth. Then do the PerformStep 10 times for every one your were doing before(i.e. If you were doing the PerformStep every 1,000 bytes do it every 10,000 bytes).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.