如何在System.IO.File.Delete中使用我的root [英] how to use my root in System.IO.File.Delete

查看:117
本文介绍了如何在System.IO.File.Delete中使用我的root的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:



Hi , i have below code :

string filename = "L:/chikardarin Website/WebApplication2/image_Logo/" + ImgName;
if (System.IO.File.Exists(filename))
{
    System.IO.File.Delete(filename);
    Response.Write("Deleted");
}





i想添加L:/ chikardarin网站/ WebApplication2 / image_Logo /

我的直接位置是../../ image_Logo



但不会采取任何行动。请帮我如何从我的网站根目录写它。



谢谢。



i would like to add inster of L:/chikardarin Website/WebApplication2/image_Logo/
my direct location which is ../../image_Logo

but it wont do any action . please help me how to write it from my web root .

thanks .

推荐答案

要获取Web root,请使用Server.MapPath并为其指定虚拟路径。



To get web root you use Server.MapPath and give it the virtual path.

String path = Server.MapPath("~/image_logo/ImageName.gif");





将返回L:\chikardarin WebSite \ WebApplication2 \ image_Logo \ ImageName.gif,假设WebApplication2是您的根。



will return L:\chikardarin WebSite\WebApplication2\image_Logo\ImageName.gif assuming that WebApplication2 is your root.


string filename = Server.MapPath("~/image_logo/" + ImgName);
if (System.IO.File.Exists(filename))
{
    System.IO.File.Delete(filename);
    Response.Write("Deleted");
}


这篇关于如何在System.IO.File.Delete中使用我的root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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