开发者

how to get the proper path using fileupload in asp. net?

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,,


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜