public void UploadTheFile(string FileName, string FilePath) { try { string output, sendData; ClientSocket.SendMessage("UPLOAD"); output = ClientSocket.ReceiveMessage(); //Normal size will be 256 if (output.Equals("SEND")) { //Sending FileName and checksum sendData = string.Format("{0}${1}", FileName, md5Checksum(FilePath)); ClientSocket.SendMessage(sendData); // Reply form server output = ClientSocket.ReceiveMessage(256); // ALLOK , FILE_EXIST //If file is already exist if (output.Equals("FILE_EXIST")) { //File already present MessageBoxResult result = MessageBox.Show("File is already exist, Do you wan't to overwrite", "Error", MessageBoxButton.YesNo); if (result.HasFlag(MessageBoxResult.No)) { ClientSocket.SendMessage("NO"); return; } ClientSocket.SendMessage("YES"); ClientSocket.ReceiveMessage(); //Receive ALLOK } else if (output.Equals("ALLOK")) { } else { MessageBoxResult result = MessageBox.Show("Same file is Exist at " + output, "Error", MessageBoxButton.YesNo); if (result.HasFlag(MessageBoxResult.No)) { ClientSocket.SendMessage("NO"); return; } ClientSocket.SendMessage("YES"); ClientSocket.ReceiveMessage(); //Receive ALLOK } // Sending FileSize FileInfo fi = new FileInfo(FilePath); ClientSocket.SendMessage(fi.Length.ToString()); output = ClientSocket.ReceiveMessage(); if (output.Equals("SENDFILE")) { //SendFile ClientSocket.SendFile(FilePath); output = ClientSocket.ReceiveMessage(); // Display in list DisplayParentData(); OpenFolder(output); MessageBox.Show("Successfully uploaded", "Output"); } } } catch (Exception) { MessageBox.Show("Server have been stop"); Environment.Exit(0); } }