/// <summary> /// This function is called when you click the View files button /// </summary> /// <param name="sender"> </param> /// <param name="e"> </param> protected void btnViewFiles_Click(object sender, System.EventArgs e) { // Creates an ShareForm object from frmShare class and // initializes it frmShare ShareForm = new frmShare(); // Get the currently selected item from the list view System.Windows.Forms.ListView.SelectedListViewItemCollection items = lvComputers.SelectedItems; // Get the IPAddress of the Selected item from IP Address // column string SelectedIP = items[0].SubItems[1].Text.Trim(); // The followinf 12 lines of code Scans through the // SERVERSEARCH list and insert the values in the List view // of the frmShare class Folder and file wise for (int i = 0; i < iSearchResult; i++) { if (0 == xmlStruct.SERVERSEARCH[i].sIPAddress.Trim().CompareTo(SelectedIP)) { ImageList imgList = new ImageList(); imgList.Images.Add(System.Drawing.Image.FromFile(Application.StartupPath + "\\Folder.ico")); imgList.Images.Add(System.Drawing.Image.FromFile(Application.StartupPath + "\\File.ico")); ShareForm.lvFiles.SmallImageList = imgList; if (xmlStruct.SERVERSEARCH[i].sFilename.EndsWith("\\")) { lvItems = ShareForm.lvFiles.Items.Insert(i, xmlStruct.SERVERSEARCH[i].sFilename); lvItems.ImageIndex = 0; } else { lvItems = ShareForm.lvFiles.Items.Insert(i, xmlStruct.SERVERSEARCH[i].sFilename); lvItems.ImageIndex = 1; } } } ///////////////////////////////////////////////////////////////// /// ShareForm.btnPrint.Enabled = false; ShareForm.btnChat.Enabled = false; // Shows the ShareForm window ShareForm.ShowDialog(); }
/// <summary> /// Invoked when the user clicks on the Open button /// </summary> /// <param name="sender"> </param> /// <param name="e"> </param> protected void btnOpen_Click(object sender, System.EventArgs e) { // Get the currently selected item from the list view System.Windows.Forms.ListView.SelectedListViewItemCollection items = lvComputers.SelectedItems; try { // if item is found or not if (0 < items.Count) { // Makes the string that is required to pass to the contructor // of the frmShare class // Appends the "(" and ")" at the begin and end of the IPAddress string SelectedIP = " (" + items[0].SubItems[1].Text + ")"; // gets the name of the computer from Computername column // of the list view string Computername = items[0].Text; // Concatenates the Computername to IP address Computername = Computername + SelectedIP; // declares a variable ShareForm of type frmShare class // and passes the Computername to it frmShare ShareForm = new frmShare(Computername); // Shows the frmShare dialog window ShareForm.Show(); } // Throws the exception else { throw new Exception("No selected computer found"); } } // cathces the exception and shows it in a message box catch (Exception err) { MessageBox.Show(err.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }