简体   繁体   中英

How to get the full Path of the file upload control in a string variable in asp .net?

I would like to get the full path of the file upload control in the string variable. The file may be stored in any location other than the root of the project. Anybody please help out.

The situation is:

string file = Path.GetFileName(ExcelFileUpload.FileName);
            if (file.EndsWith(".xlsx"))
            {
                // Reading from a binary Excel file (format; *.xlsx)
                FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read);

It sounds like you're actually asking for the original path to the file on the client machine .

This is (a) useless (it's on a different computer) and (b) impossible to get (the browser doesn't tell you it).

What are you trying to do?

You could try somehting like this : (where MyFileUploader is your FileUpload control)

                string fileBasePath = Server.MapPath("~/");
                string fileName = Path.GetFileName(this.MyFileUploader.FileName);
                string fullFilePath = fileBasePath + fileName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM