Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This is my deceleration part in string.
C#
string str=Combobox1.SelectedIndex.ToString();

This is my class file how to get the string value in str?
C#
class FTClientCode
       {

           public static string curMsg = "Idle";
           public static void SendFile(string fileName)
           {
               try
               {


                   IPAddress[] ipAddress = Dns.GetHostAddresses(str);
                   IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656);
                   Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);


                   string filePath = "";

                   fileName = fileName.Replace("\\", "/");
                   while (fileName.IndexOf("/") > -1)
                   {
                       filePath += fileName.Substring(0, fileName.IndexOf("/") + 1);
                       fileName = fileName.Substring(fileName.IndexOf("/") + 1);
                   }


                   byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
                   if (fileNameByte.Length > 850 * 1024)
                   {
                       curMsg = "File size is more than 850kb, please try with small file.";
                       return;
                   }

                   curMsg = "Buffering ...";
                   byte[] fileData = File.ReadAllBytes(filePath + fileName);
                   byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
                   byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);

                   fileNameLen.CopyTo(clientData, 0);
                   fileNameByte.CopyTo(clientData, 4);
                   fileData.CopyTo(clientData, 4 + fileNameByte.Length);

                   curMsg = "Connection to server ...";
                   clientSock.Connect(ipEnd);

                   curMsg = "File sending...";
                   clientSock.Send(clientData);

                   curMsg = "Disconnecting...";
                   clientSock.Close();
                   curMsg = "File transferred.";

               }
               catch (Exception ex)
               {
                   if (ex.Message == "No connection could be made because the target machine actively refused it")
                       curMsg = "File Sending fail. Because server not running.";
                   else
                       curMsg = "File Sending fail." + ex.Message;
               }

           }
       }
Posted
Updated 28-Feb-12 3:59am
v2
Comments
ckulasekaran 28-Feb-12 0:56am    
Your question is same as this http://www.codeproject.com/Questions/337051/how-to-get-the-string-value-in-class-file

Any relation-between two off them?
Sergey Alexandrovich Kryukov 28-Feb-12 1:05am    
Could you explain: why this question is nearly identical to this one:
http://www.codeproject.com/Questions/337051/how-to-get-the-string-value-in-class-file
???

--SA
Keith Barrow 28-Feb-12 3:44am    
Two people doing the same homework?
Sergey Alexandrovich Kryukov 28-Feb-12 13:09pm    
It happened before many time, but people (from different account) never sent identical code.
I really want some explanation from OP.
--SA

1 solution

Set this in Combobox1 selection changed event[^].
string str=Combobox1.SelectedIndex.ToString();
 
Share this answer
 
Comments
sudhaharjagan 28-Feb-12 0:56am    
how to get the string value in class file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900