【发布时间】:2018-10-08 19:44:13
【问题描述】:
我正在使用 ASPX 构建一个简单的页面。
在此页面中,我显示了一个文件组件。使用此组件,用户可以选择本地文件:
<div class="row">
<form class="form-horizontal">
<div class="form-group">
<input type="file" id="selectFile" >
</div>
</form>
</div>
现在,我想以编程方式设置此文件。所以从我的 Default.aspx.cs 代码中我有这个:
protected void Page_Load(object sender, EventArgs e)
{
String s = Request.QueryString["idEsame"];
//RECUPERO IL FILE ED IL PATH DEL FILE
string[] fileEntries = Directory.GetFiles("C:\\Users\\michele.castriotta\\Desktop\\deflate_tests");
foreach (string fileName in fileEntries)
{
// here i need to compare , i mean i want to get only these files which are having these type of filenames `abc-19870908.Zip`
if(fileName == "file")
{
}
}
}
现在如果文件名是“文件”,那么我想在页面上自动加载这个文件。
我该怎么做?
【问题讨论】:
-
How to Ask。你想要所有的拉链吗? stackoverflow.com/questions/3152157/…
-
或者可能是一个特定的模式? regex101.com/r/l6AULc/1 。一个简单的 Where 子句就足够了
-
您是否知道您的代码将在服务器上的目录中查找,而不是在客户端上?
-
Directory.GetFiles选择服务器端的文件,而不是客户端目录。如果您想允许客户端预览上传的文件,请改用FileUpload控件。 -
我想从服务器获取文件。然后在客户端加载这个文件