简体   繁体   中英

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. 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. You can use HttpServerUtility.MapPath for that. 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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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