问题描述
我在下拉列表中显示所有项目名称如下
string sourceDirectory = Server.MapPath(〜/);
DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectory);
var aspxFiles = new List< string>(Directory.GetFiles(sourceDirectory,* .aspx,SearchOption.AllDirectories));
foreach(字符串currentFile in aspxFiles)
{
this.ddllink.Items.Add(currentFile);
}
当我在下拉列表输出中运行如下
E:Projects \接待'\\Default.aspx
但我想在下拉列表中显示如下Default.aspx
i希望在\之后拆分。
我怎样才能在asp.net中使用c#。
在下拉列表中我想要输出如下
Default.aspx
I am displaying all the project name in dropdownlist as follows
string sourceDirectory = Server.MapPath("~/");
DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectory);
var aspxFiles = new List<string>(Directory.GetFiles(sourceDirectory, "*.aspx", SearchOption.AllDirectories));
foreach (string currentFile in aspxFiles)
{
this.ddllink.Items.Add(currentFile);
}
When i run in dropdownlist output as follows
E:Projects\Reception\Default.aspx
But i want in dropdownlist as follows Default.aspx
i want to split after \.
for that how can i do in asp.net using c#.
In dropdownlist i want output as follows
Default.aspx
推荐答案
var name=@"E:Projects\Reception\Default.aspx\default1.aspx";
Console.WriteLine(System.IO.Path.GetFileName(name));
和OP将是
and OP will be
default1.aspx
谢谢
Thanks
string sourceDirectory = Server.MapPath("~/");
DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirectory);
var aspxFiles = new List(Directory.GetFiles(sourceDirectory, "*.aspx",SearchOption.AllDirectories));
foreach (string currentFile in aspxFiles)
{
this.ddllink.Items.Add(Path.GetFileName(currentFile));
}
这篇关于如何在C#中拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!