2

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);
6
  • 1
    It's very unclear what you're trying to do. Please show us what you've tried and explain what you expect. Commented Jun 17, 2013 at 13:53
  • @Bartdude: My psychic debugging skills tell me that he actually wants to save the file, but doesn't realize that the bytes are sent to the server. (and may not realize that there are two machines involved) Commented Jun 17, 2013 at 13:54
  • I also think it's what he's trying to do, but who knows ? ;-) Commented Jun 17, 2013 at 13:55
  • I have updated the question with the situation where I want to apply the concept... Commented Jun 17, 2013 at 13:56
  • msdn has a straightforward example of what you are asking for: msdn.microsoft.com/en-us/library/… Commented Jun 17, 2013 at 14:28

2 Answers 2

3

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Just to mention - IE provides full client-side file path. And yes - it is meaningless for the server-side code.
@Igor: Not in recent versions, AFAIK.
1

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;

2 Comments

May I know what exactly is this.fileName and this.fullFilePath.
Hi PrabuR , they are just variables, you can set it to any variable name you like i.e. string myFullPath = fileBasePath + this.fileName; the were prefixed with this. in my example as i had them created outside the method , but in your case you probably use a local variable. I'll update the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.