how to do i get the unc path value from text textbox

  • Thread starter Thread starter DON JEFFERS
  • Start date Start date
D

DON JEFFERS

Guest
Hello all,

I am working on an application that connects to a unc path with credentials. My application scans the network for shared computers then the user selects the computer from a listbox and from the listbox the IP address goes to a textbox.

In this textbox resides the IP address I would like to know how to open a unc path from a textbox on button click I have some code below to show what I have so far. Button1 is supposed to browse the unc path from IPtxt (which is the textbox that the IP address resides in).

If someone can point me in the right direction or an example of how I can go about doing this it would be greatly appreciated. Thank you for your time.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Net.Configuration;
using System.Runtime.InteropServices;

namespace ListNetworkComputers
{
/// <summary>
/// A simply test form that creates a new NetworkBrowser
/// object, and displays a list of the network computers
/// found by the NetworkBrowser
/// </summary>
public partial class frmMain : Form
{
/// <summary>
/// Constructor
/// </summary>
public frmMain()
{
InitializeComponent();
}


private void frmMain_Load(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{

}

private void Scanbtn_Click(object sender, EventArgs e)
{
Process netUtility = new Process();

netUtility.StartInfo.FileName = "net.exe";

netUtility.StartInfo.CreateNoWindow = true;

netUtility.StartInfo.Arguments = "view";

netUtility.StartInfo.RedirectStandardOutput = true;

netUtility.StartInfo.UseShellExecute = false;

netUtility.StartInfo.RedirectStandardError = true;

netUtility.Start();



StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);



string line = "";

while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("\\"))
{


string pcname = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper();
string myIP = Convert.ToString(System.Net.Dns.GetHostByName(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper()).AddressList[0].ToString());
string fullname = "PC Name : " + pcname + " IP Address : " + myIP;
listBox1.Items.Add(pcname);
listBox2.Items.Add(myIP);
}
}

streamReader.Close();
netUtility.WaitForExit(1000);


}

private void button1_Click_1(object sender, EventArgs e)
{
Application.Exit();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{

string ipaddress = listBox2.GetItemText(listBox2.SelectedItem);
System.Net.IPAddress ip = System.Net.IPAddress.Parse(ipaddress);

IPtxt.Text = listBox2.SelectedItem.ToString();

// string text = listBox2.GetItemText(listBox2.SelectedItem);

// label1.Text = listBox2.SelectedItem.ToString();

}

private void cTextBox1_TextChanged(object sender, EventArgs e)
{

}
}
}

Continue reading...
 
Back
Top