获取服务端的内容

Posted 加德满都的风铃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取服务端的内容相关的知识,希望对你有一定的参考价值。

 

 

 

 

 

 

#region 记录日志
private void WriteLog(Exception ex, string msg)
{
try
{
string applicationStartupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string fileName = Path.Combine(applicationStartupPath, "Log.txt");

using (StreamWriter writer = new StreamWriter(fileName, true, System.Text.Encoding.UTF8, 1024))
{
writer.WriteLine(String.Empty);
writer.WriteLine(msg);
if (ex == null)
{
writer.WriteLine("时间: {0}", DateTime.Now.ToString());
}
else
{
writer.WriteLine("出错时间: {0}", DateTime.Now.ToString());
writer.WriteLine("出错信息: {0}", ex.Message);
writer.WriteLine("详细信息: {0}", ex.StackTrace);
}
writer.WriteLine(String.Empty);
writer.WriteLine("*********************************************************************");
writer.Flush();
writer.Close();
}
}
catch
{ }
}
#endregion

 

 

 


private void Form2_Load(object sender, EventArgs e)
{

}
private string x = default(string);

private void button1_Click(object sender, EventArgs e)
{
x = txtUrl.Text;

treeView1.Nodes.Clear();//清楚之前绑定的数据
string[] Directory = System.IO.Directory.GetDirectories(x);//获取路径下的所有文件夹

for (int i = 0; i < Directory.Length; i++)
{
string aa = Directory[i];
DirectoryInfo directoryinfo = new DirectoryInfo(Directory[i]);
TreeNode Tn = new TreeNode(directoryinfo.Name);// 把文件夹的名称显示出来
Tn.ImageIndex = Tn.SelectedImageIndex;//给文件夹添图标
treeView1.Nodes.Add(Tn);//添加节点


}


}


/// <summary>
/// 折叠节点后发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeView1_AfterCollapse(object sender, TreeViewEventArgs e)
{
if (e.Node == treeView1.Nodes[0])
{
return;
}
e.Node.SelectedImageIndex = 1;
e.Node.ImageIndex = 1;
}
/// <summary>
/// 节点展开后发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
{
if (e.Node == treeView1.Nodes[0])
{
return;
}
e.Node.SelectedImageIndex = 2;
e.Node.ImageIndex = 2;
}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
string str = x + treeView1.SelectedNode.FullPath;
string[] File1 = System.IO.Directory.GetFileSystemEntries(str); //获取路径下的所有文件
//string[] f1 = Directory.GetFiles(str);
//foreach (string item in f1)
//{
// FileInfo fo = new FileInfo(item);
// treeView1.Nodes.Add(fo.Name);
//}

//string[] File = System.IO.Directory.GetFiles(); //获取路径下的所有文件

//for (int i = 0; i < File.Length; i++)
//{
// DirectoryInfo directoryinfo = new DirectoryInfo(File[i]);
// TreeNode Tn = new TreeNode(directoryinfo.Name);// 把文件的名称显示出来
// Tn.ImageIndex = Tn.SelectedImageIndex;//给文件夹添图标
// treeView1.SelectedNode.Nodes.Add(Tn);//添加节点
// //treeView1.Nodes["1"].Nodes.Add(File);
// //treeView1.Nodes.Find("1", true)[0].Nodes.Add("File");
//}
foreach (string ss in File1)
{
DirectoryInfo directoryinfo = new DirectoryInfo(ss);
//TreeNode Tn = new TreeNode(directoryinfo.Name);// 把文件的名称显示出来

this.treeView1.SelectedNode.Nodes.Add(directoryinfo.Name);
}
}
catch (Exception)
{
return;
}

}

private void button2_Click(object sender, EventArgs e)
{
string x = txtUrl.Text;

treeView1.Nodes.Clear();//清楚之前绑定的数据

string[] File = System.IO.Directory.GetFiles(x);//获取路径下的所有文件
for (int i = 0; i < File.Length; i++)
{

DirectoryInfo directoryinfo = new DirectoryInfo(File[i]);
TreeNode Tn = new TreeNode(directoryinfo.Name);// 把文件的名称显示出来
Tn.ImageIndex = Tn.SelectedImageIndex;//给文件添图标
treeView1.Nodes.Add(Tn);//添加节点
}
}


}
}

以上是关于获取服务端的内容的主要内容,如果未能解决你的问题,请参考以下文章

在 WCF 服务 C# 的服务器端获取客户端的 Mac 地址不重复(在 WCF 3.0 中获取客户端 IP 地址)

服务器端获取客户端的IP地址(当客户端调用由Axis开发的WebService)

客户端js和服务器端js的区别

C#.net Sockets,服务端怎么知道客户端的IP和端口?

java服务器端,通过HttpServletRequest可以获取手机浏览器端的imsi吗?

Node访问服务器端静态资源