我在asp中写了一个读文本文件 ,我在本机上都完全正确,可是我在其他机器访问时就不对了.
求求各位了,急死人了.
if(filePath.PostedFile.FileName != "")
{
txtFilePath =filePath.PostedFile.FileName;
fileExtName = txtFilePath.Substring(txtFilePath.LastIndexOf(".")+1,3); if(fileExtName !="txt" && fileExtName != "TXT")
{
Response.Write("请选择文本文件");
}
else
{
StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default);
txtContent.Text = fileStream.ReadToEnd();
fileStream.Close();
}
}

解决方案 »

  1.   

    报什么错应该是你的上传文件夹权限不够
    把该文件设为everyone读写权限
      

  2.   

    StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default);
    txtContent.Text = fileStream.ReadToEnd();
    fileStream.Close();------------------------------------
    这一句在你本机上时,因为你本机是服务器,也是客户端,所以等于读取本机的文件,所以没有错。
    在其他机器上的时候,等于用服务器的程序去读取客户机的文件,当然存在权限的问题
    解决方法可能只能如上面老兄所说。.net中可以用身份模拟
    可惜asp中没有
      

  3.   

    下面是页面报错的内容
    Server Error in '/' Application.
    --------------------------------------------------------------------------------Runtime Error 
    Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>
     Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>