检查服务器上是否存在文件 [英] Check if a file exists on the server

查看:111
本文介绍了检查服务器上是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查服务器上是否有文件,并且ASP.NET网页后面带有C#代码.我知道该文件确实存在,因为我事先已将其以一段代码形式放在服务器上.谁能看到为什么找不到该文件.这是代码:

I am trying to check if a file is on the server with the C# code behind of my ASP.NET web page. I know the file does exist as I put it on the server in a piece of code before hand. Can anyone see why it is not finding the file. This is the code:

wordDocName = "~/specifications/" + Convert.ToInt32(ViewState["projectSelected"]) + ".doc";
ViewState["wordDocName"] = wordDocName;
if (File.Exists(wordDocName))
{
    btnDownloadWordDoc.Visible = true;
}
else
{
    btnDownloadWordDoc.Visible = false;
}

推荐答案

文件路径应该是物理的而不是虚拟的.使用

the file path should be physical not virtual. Use

if (File.Exists(Server.MapPath(wordDocName)))

这篇关于检查服务器上是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆