2

I'm having problem on getting the file path using file upload. When I tested to upload a file on the file upload, I've noticed that my file upload is getting the wrong path. The right path is C:\RightPath\B1.txt but the I check it its getting the wrong path which is 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\B1.txt'..

here's my code behind...

        string OasisPath = Path.GetFullPath(cmdUpload.FileName);
        StreamReader OasisFile = new StreamReader(OasisPath);
        string B1String = OasisFile.ReadLine();
        OasisFile.Close();

I also tried this one..

    string OasisPath = Server.MapPath(cmdUpload.FileName);
    StreamReader OasisFile = new StreamReader(Server.MapPath(cmdUpload.FileName)); // I get this error Could not find file 'C:\Rightpath\B1.txt'
    string B1String = OasisFile.ReadLine();
    OasisFile.Close();

Please advice me...

thanks,,

2
  • Are you trying to get the full path of the file from the machine it came from, or are you trying to figure out where it is on your server? You can't get the path of the source, for security and other reasons. Commented Jun 3, 2011 at 14:16
  • @DOK, I see.. yes, I can get the full path. I have no idea on the server path.. sorry.. Commented Jun 3, 2011 at 14:17

1 Answer 1

5

You need to explicitly set the path of the file when you save it. The server doesn't know what path the file was stored in on the client machine. If you don't specify a path it will just save it in the current environment's default path.

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

Comments

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.