简体   繁体   English

如何获取要从服务器删除的文件的路径

[英]how to get path of the file to be deleted from the server

i want to delete a file present in directory on the server. 我想删除服务器目录中存在的文件。 I have tried following code but code inside the file.exist never runs. 我尝试了以下代码,但是file.exist内部的代码从未运行。 It always skips it showing me that file does not exist. 它总是跳过它,向我显示该文件不存在。 But file is present. 但是文件存在。 can smone please help me. 可以纵容,请帮助我。 Thanx in advance 提前感谢

string filename = "Template\\copy.jpg";
        if(System.IO.File.Exists(filename))
        {
            System.IO.File.Delete(filename);
        }

尝试

string fileName = Server.MapPath(@"/Template/copy.jpg");

You can use Server.MapPath to get the path. 您可以使用Server.MapPath来获取路径。 eg 例如

string filename = Server.MapPath("~/Template/copy.jpg");
System.IO.File.Delete(filename);

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

相关问题 如何在folderbrowserdialog中获取服务器文件路径? - How to get server file path in folderbrowserdialog? 从服务器托管应用程序时如何获取用户文件的本地桌面路径? - How to get the local desktop path of the users file when the application is hosted from server? 如何从项目路径获取WinRT中的文件? - How to get file in WinRT from project path? 如何从文件夹WPF获取文件路径? - How to get file path from folder wpf? 如何从IsolatedStorage获取ShareMediaTask的文件路径 - How to get file path from IsolatedStorage for ShareMediaTask 如何从 OpenFileDialog 和 FolderBrowserDialog 获取文件路径? - How to get file path from OpenFileDialog and FolderBrowserDialog? 从实体框架上下文获取SQL Server Compact文件的路径? - Get path to SQL Server Compact file from Entity Framework context? 如何从基本路径和包含“..”的相对文件获取绝对文件路径? - How to get absolute file path from base path and relative containing “..”? 如何从保存在 SQL Server 数据库中的文件路径下载文件? - How to download file from file path saved in a SQL Server database? 如何在IIS服务器中获取上传文件的临时路径 - how to get Temporary path of the uploaded file in the IIS server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM