如何从ASP文件的完整路径:文件上传? [英] How to get the full path of a file from asp: file upload?

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

问题描述

我试图让使用asp.net文件上传功能的文件的完整路径。我使用C#在Visual Basic 2010年我之所以想要的完整路径是因为我其实是想获得有关的文件夹的包含文件,因为该计划的信息在网站的项目工作是用第三方比较工具,UltraCompare中比较两个文件夹的内容,然后该比较的结果转移到我们的数据库。

在理想情况下,我想一个功能,使用户能够浏览一个文件夹,而不是一个文件,但据我可以从我的谷歌搜索出来,这是不可能在.NET 4.0中,这是我的版本M使用。

我不知道,如果是必要的,甚至在所有使用文件上传控件,因为所有我需要的是目录的文件路径。不过,我想的东西,使用户能够搜索使用GUI浏览器窗口中的文件作为完整的文件路径不是打字。

我显然与C#.NET和编程一般一个巨大的小白,所以任何意见或建议将不胜AP preciated。下面是一些示例code我从别的地方复制和粘贴。在注释中的东西只是我的尝试(失败)得到该文件的路径不同的方法。

 如果(File1.HasFile)
        {
            尝试
            {
                //字符串filepath1 = Path.GetFullPath(File1.PostedFile.FileName);
                字符串filepath1 = Path.GetFileName(File1.FileName);
                File1.SaveAs(使用Server.Mappath(〜/)+ filepath1);
                //StatusLabel.Text =上传状态:上传的文件(S)!;
                的Response.Write(上传状态:文件(S)上传< BR />!);
                的Response.Write(filepath1);
            }
            赶上(异常前)
            {
                StatusLabel.Text =上传状态:文件(S)不能上载出现下列错误:+ ex.Message;
                。//Response.Write(\"Upload状态:文件(S)不能上载出现下列错误:+ ex.Message +< BR />中);
            }


解决方案

HTML不给你比原来的文件名的任何其他。任何额外的信息,如文件夹路径或属性,将违反客户端的安全和隐私。你需要使用别的东西,像一个ActiveX控件或的Adobe Flash得到你之后的数据。

I'm trying to get the full path of a file using the file upload feature in asp.net. I'm working on a website project using C# in Visual Basic 2010. The reason I want the full path is because I'm actually trying to get information on the folder which contains the file, because the plan is to compare the contents of two folders using a third-party compare tool, UltraCompare, and then transfer the results of that comparison into our database.

Ideally, I'd like a feature that enables the user to browse for a folder rather than a file, but as far as I can tell from my googling, this is not possible in .net 4.0, which is the version I'm using.

I'm not sure if it's even necessary to use the file upload control at all, as all I require is the filepath of the directory. However, I would like something that enables the user to search for a file using a GUI browser window as opposed to typing in the full file path.

I'm obviously a huge noob with C# .net and programming in general, so any advice or suggestions would be greatly appreciated. Here is some sample code I copy-and-pasted from somewhere else. The stuff in comments is just me trying out (unsuccessfully) different methods for getting the file path.

if (File1.HasFile)
        {
            try
            {
                //string filepath1 = Path.GetFullPath(File1.PostedFile.FileName);
                string filepath1 = Path.GetFileName(File1.FileName);
                File1.SaveAs(Server.MapPath("~/") + filepath1);
                //StatusLabel.Text = "Upload status: File(s) uploaded!";
                Response.Write("Upload status: File(s) uploaded! <br />");
                Response.Write(filepath1);
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file(s) could not be uploaded. The following error occured: " + ex.Message;
                //Response.Write("Upload status: The file(s) could not be uploaded. The following error occured: " + ex.Message + "<br />");
            }

解决方案

html does not give you anything other than the original file name. any additional information, such as folder path or properties, would be a breach of the client's security and privacy. You'll need to use something else, like an activex control or adobe flash to get the data you are after.

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

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