/// <summary>
/// 选择一个文件路径
/// </summary>
/// <returns></returns>
[HttpPost]
public ActionResult SelectPath()
{
try
{
//选择文件夹开始
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";
var Path = "";
Thread t = new Thread((ThreadStart)(() =>
{
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
Path = foldPath;
// MessageBox.Show("已选择文件夹:" + foldPath, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
//选择文件夹结束
return Json(new
{
Success = true,
Message = "选择成功!"
});
}
catch (Exception)
{
return Json(new
{
Success = false,
Message = "系统错误!"
});
}
}
C# .NET MVC /Web浏览器如何选择本地文件夹路径。
最新推荐文章于 2024-09-27 16:45:26 发布