我的代码是System.IO.File.Delete(this.Server.MapPath("..")+@"/VideoDemo/Video/"+fileName); 不知道这样是否是正确的?
还有判断文件存在的问题,为什么也是要用绝对路径,可以用相对路径解决吗??如
if(System.IO.File.Exists(this.Server.MapPath("..")+@"\VideoDemo\Video\"+fileName)==false)因为我怕别人访问时访问不了呀?
还有判断文件存在的问题,为什么也是要用绝对路径,可以用相对路径解决吗??如
if(System.IO.File.Exists(this.Server.MapPath("..")+@"\VideoDemo\Video\"+fileName)==false)因为我怕别人访问时访问不了呀?
解决方案 »
- DropDownList问题
- q显示
- dropdownlist.SelectedValue=空值的时候怎么给他赋值为0
- 如何在DataSet或GridView控件中替换内容
- 请教,关于GridView中超链接的问题
- 母版页主要用在什么地方
- [共享+散分]ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- 谁能教我如何在ASP.NET里面使用OLEDB的连接方式使用ORACLE的存储过程?多谢
- 如何控制datagrid控件页导航的高度
- DataGrid自动分页翻不了页,求大侠看看问题所在?急用
- 问一下div+CSS在ASP.NET里做<LI>的循环,用什么显示?
- 采集文章标题怎么做?
另外,建议用System.IO.Path.Combine来拼凑文件名
这样可以减少\出现丢失或重复的问题
string picturePath = GetPicturePath(goods_id);
if (File.Exists(this.Server.MapPath(picturePath)))
{
File.Delete(this.Server.MapPath(picturePath));
}
protected string GetPicturePath(int goods_id)
{
BLL.zqu_goods_goods bll = new zqu_goods_goods();
DataSet ds = bll.GetList(" goods_id='" + goods_id + "'");
string picPath = "~/uploadfile/" + ds.Tables[0].Rows[0][10].ToString();
return picPath;
}
例如:
c:\www\1.txt
可以用相对路径。
string path = Server.MapPath("~/UploadImages/fwys/");
string file = path + filename;
if (File.Exists(file))
{
File.Delete(file);
Common.Message(this,"附件删除成功!");
}
Server.MapPath()就是获取绝对路径,你要把文件放在IIS有权限访问的目录下(一般在web目录下就可以,要删除的话就必须要有写权限).
所以,你所谓的担心是多余也是没用的.你上面的拼接也是多此一举.