如何在asp中使用fileupload获取正确的路径.净?

ghi*_*hie 2 c# file-upload

我在使用文件上传获取文件路径时遇到问题.当我测试上传文件上传文件时,我注意到我的文件上传路径错误.正确的路径,C:\RightPath\B1.txt但我检查它是错误的路径,是'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\B1.txt'..

这是我的代码背后......

        string OasisPath = Path.GetFullPath(cmdUpload.FileName);
        StreamReader OasisFile = new StreamReader(OasisPath);
        string B1String = OasisFile.ReadLine();
        OasisFile.Close();
Run Code Online (Sandbox Code Playgroud)

我也试过这个..

    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();
Run Code Online (Sandbox Code Playgroud)

请指教我......

谢谢,,

Jas*_*son 5

保存文件时,需要显式设置文件的路径.服务器不知道文件存储在客户端计算机上的路径.如果您没有指定路径,它只会将其保存在当前环境的默认路径中.