如何从文本框中获取unc路径值 [英] How to do I get the unc path value from text box
问题描述
大家好,
我正在使用凭据连接到unc路径的应用程序。我的应用程序扫描网络以查找共享计算机,然后用户从列表框中选择计算机,并从列表框中将IP地址转到文本框。
在这个文本框中保留了我想知道如何在按钮点击时从文本框打开unc路径的IP地址我在下面有一些代码来显示我有什么至今。 Button1应该从IPtxt(这是一个文本框)浏览unc路径。
如果有人可以指出我正确的方向,或者我可以如何做到这一点,我将不胜感激。感谢您的时间。
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 a textbox).
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)
{
}
}
}
我尝试了什么:
我附加到我的代码题。感谢您花时间查看我的代码并帮助我。亲切的问候。
What I have tried:
I the code attached to my question. Thank you for taking your time looking over my code and helping me kind regards.
推荐答案
如果我正确地提出您的问题,您想通过您的应用程序打开一个unc文件夹吗?
如果是这样,以下stackoverflow可能会有所帮助,因为它为给定路径打开一个Windows资源管理器
< a href =https://stackoverflow.com/questions/7559867/open-remote-shared-folder-with-credentials> vb.net - 使用凭据打开远程共享文件夹 - Stack Overflow [ ^ ]
我知道它是VB.NET但应该很容易转换为C#
If I get your question properly you want to open a unc folder via you application?
if so the following stackoverflow may help as it opens a windows explorer for a given path
vb.net - Open remote shared folder with credentials - Stack Overflow[^]
I know that it is VB.NET but should be very easily converted to C#
这篇关于如何从文本框中获取unc路径值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!