简体   繁体   English

如何将此.NET代码更改为File.Exists?

[英]How can I change this .NET code to File.Exists?

I am working with a framework written in .NET and I do not know .NET. 我正在使用.NET编写的框架,我不知道.NET。 I just need to change this one line where it checks to see if a variable exists, and I need to change it to instead just check on the server to see if the file itself exists. 我只需要更改这一行,检查变量是否存在,我需要将其更改为只需检查服务器以查看文件本身是否存在。

Here is what is there now: 这是现在的情况:

@if (!string.IsNullOrEmpty(Model.DrawingLink2){

Is this the correct code to change it to check if the file exists instead? 这是正确的代码来更改它以检查文件是否存在?

@if (File.Exists(/Portfolio/@(Model.FileNumber)/Images/Large_@(Model.FileNumber)_1.jpg))

You need to map that file, relative to the root of the web application, to the physical file system. 您需要将该文件(相对于Web应用程序的根目录)映射到物理文件系统。 You can use HttpServerUtility.MapPath for that. 您可以使用HttpServerUtility.MapPath You also need quotes around string literals. 您还需要围绕字符串文字的引号。 The process running the code also needs read access to the directory (very likely the case, just mentioning it to be complete). 运行代码的进程还需要对目录的读访问权(很可能是这种情况,只是提到它是完整的)。

@if (File.Exists(HttpServerUtility.MapPath("/Portfolio/@(Model.FileNumber)/Images/Large_@(Model.FileNumber)_1.jpg"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM