如何从FileUpload控件获取/读取文件名? [英] how to get/read file name from FileUpload control?

查看:94
本文介绍了如何从FileUpload控件获取/读取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击Borwse按钮并选择文件后从FileUpload控件获取或读取文件名.例如,当单击浏览按钮时,我可以从计算机中的任何位置浏览文件,例如,在C://video/al.avi中选择视频文件名al.avi.所以我如何获取和读取视频的名称并将其显示在标签控件中.

how to get or read the file name from FileUpload control when borwse button clicked and a file is selected. for example, when browse button clicked, i can browse a file from any location in my computer, for example select video file name al.avi in C://video/al.avi. so how can i get and read the video's name and display it in label control.

推荐答案

回发到服务器时,您将在文件中获取数据以及FileUpload控件中的文件名.

When you PostBack to the server you get the data in the file as well as the file name in the FileUpload control.

var fileName = FileUpload1.PostedFile.FileName;

这将为您提供fileName部分"al.avi".您可以在标签中显示它.

This will give you the fileName part 'al.avi'. You can display this in a label.

这是一个文件上传示例,可以帮助您入门.

Here is a FileUpload example to get you started.

这篇关于如何从FileUpload控件获取/读取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆