获得的文件的绝对路径上传 [英] Get the absolute path of a file to be uploaded

查看:133
本文介绍了获得的文件的绝对路径上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是快把我逼疯了,我觉得我应该知道这一点,但由于某些原因,它只是没有向我涌来。我走遍了相关的问题,但没有骰子。

This is driving me crazy, and I feel like I should know this, but for some reason it's just not coming to me. I scoured the related questions but no dice.

我使用的名为 theFile (ASP.NET)一个简单的FileUpload控件上传文件。我试图获取文件的绝对路径,但 thefile.PostedFile.FileName thefile.FileName 是完全相同,只是文件的名称,没有路径!我不能使用,因为使用Server.Mappath我会在不同的服务器上保存此文件(通过一个Web服务通过字节数组传递)。

I am uploading a file using a simple FileUpload control named theFile (ASP.NET). I'm trying to get the absolute path of the file, but thefile.PostedFile.FileName and thefile.FileName are the exact same, just the file name, no path! I can't use Server.MapPath because I will be saving this file on a different server (transferring via byte array through a webservice).

它打破了这一行:

Dim fStream As New FileStream(thefile.FileName, FileMode.Open, FileAccess.Read)

,因为它走的是文件名,它映射到我的VS的相对路径!我需要的绝对路径...

because it is taking the filename and mapping it to the relative path of my VS! I need the absolute path...

谢谢,我真的不是,即使有时可能会出现方式的n00b:\\

Thanks, I'm really not a n00b even though sometimes it may appear that way :\

推荐答案

通过HTTP上传永远不会包含远程(客户端)的计算机上的完整路径的文件 - 它可以放弃对他们的目录结构的信息,因此被认为是存在安全隐患。此外,它会是什么用呢?如果有人上传你在互联网上的文件,为什么你试图打开本地(asp.net服务器)上FILESTREAM机,他们的机器上存在的路径?

A file uploaded through HTTP will never contain the full path on the remote (client) machine - it could give away information about their directory structure, and so is considered a security risk. Plus, what use would it be? If someone is uploading you a file from over the internet, why would you be trying to open a filestream on your local (asp.net server) machine to the path that existed on their machine?

上传的文件实际上是一样请求的一部分的字节流来通过。您需要访问<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.filebytes.aspx\">FileBytes该控件的属性来获取文件,或致电另存为()方法将其保存到服务器。你的情况,你很可能只是得到字节并把他们关到Web服务调用,你需要做。

Uploaded files actually come through as a stream of bytes as part of the request. You need to access the FileBytes property of the control to get the file, or call the SaveAs() method to save it to the server. In your case, you could probably just get the bytes and send them off to the webservice call you need to make.

这篇关于获得的文件的绝对路径上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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