如何从FileUpload获取路径? [英] How to get path from FileUpload?

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

问题描述

我的网页中有一个Fileupload控件,我正在从用户那里获取输入文件

我想获取输入文件的路径,我不保存(即上传文件)

如何在不从fileupload上传文件的情况下获取文件的路径?

我已经尝试过

I have a Fileupload control in my Web page,I am taking an input file from user

I want to get the path of the input file,I am not saving(ie uploading the file)

How can i get the path of the file without uploading the file from fileupload?

I have tried

Server.MapPath(FileUpload.FileName);



但是它返回的文件名是我想要的,没有文件名



but it is returning path with filename i want without file name

推荐答案

http://msdn.microsoft.com/zh-CN/library/ms227669%28v = VS.100%29.aspx#Y456 [ http://asp.net-tutorials.com/controls/file-upload-control/ [< ^ ]
使用ASP.NET上传文件 [
http://msdn.microsoft.com/en-us/library/ms227677.aspx[^]
http://msdn.microsoft.com/en-US/library/ms227669%28v=VS.100%29.aspx#Y456[^]
http://asp.net-tutorials.com/controls/file-upload-control/[^]
File Upload with ASP.NET[^]

Above links will help you to understand.


u可以尝试使用此代码获取上传文件的路径.
哦,如果您的应用程序是Web应用程序,那么您必须
上传文件后回发您的网页.

u can try to get upload file path use this code.
ohhh please if your application is web application then u must
postback your web page after upload a file.

if (fUpload.PostedFile != null)
{                                                                                 
    HttpPostedFile ciFile = fUpload.PostedFile;                            
    string sFileName = System.IO.Path.GetFileName(ciFile.FileName);
    string sFile = System.IO.Path.GetFileNameWithoutExtension(sFileName);
    string sExtension = System.IO.Path.GetExtension(sFileName);            
}




由于FileUpload Control只是一个简单的<input type="file" />,因此不上传文件就不可能获得文件路径(而且上传不应该改变这种行为吗?).

同样,大多数现代浏览器都将阻止JavaScript对全路径访问的访问.但是也许您的系统有些运气.

这是一个起点:
http://rattomago.wordpress.com/2009 /02/18/accessing-filepath-in-html-input-element-via-javascript/ [
Hi,

Since the FileUpload Control is just a simple <input type="file" />, there is no possibility to get the file path without uploading the file (also the upload should not change this behaviour?).

Also most of the modern browsers will block the access to the full-path access by JavaScript. But perhaps you have some luck on your systems.

Here is a starting point:
http://rattomago.wordpress.com/2009/02/18/accessing-filepath-in-html-input-element-via-javascript/[^]

(this is only usable in a intranet environment where you can update the browser settings to allow the full-path access).

Hope this helps.

Best regards and happy coding,
Stops


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

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