FileInfo不会从联机服务器中删除文件 [英] FileInfo not deleting files from online server

查看:85
本文介绍了FileInfo不会从联机服务器中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的所有人

我几天前问过这个问题.但是没有这样的答复可以解决我的问题.
当我在本地系统上运行时,我的代码从本地计算机上删除文件.当我在线(互联网)运行相同的代码时.尽管我正在删除文件的文件夹中具有读写权限.它会创建文件正在使用中的异常.
我删除该文件的代码如下.代码很简单.我在数据库中有对目录中图片的引用.目录中的所有图片都是使用系统上传的.我必须从数据库中获取要删除的缩略图和完整图像的引用,并将这两个引用放置在列表中

Respected EveryOne

I asked this question some days ago. but no such reply came that can solve my problem.
My code when i run on local system, deletes files from the local machine. when i run the same code online (Internet). Despite of read write access in the folder where i am deleting the file. it creates exception that the file is in use.
My code to delete that files are as under. The code is simple. I have references in the database to pictures in the directory.All the pictures in the directory are uploaded using the system. I have to get the references which i have to delete for both the thumbnail image and full images from the database and repose both of the references in list

protected void grdAllCars_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{ 
var dataKey = grdAllCars.DataKeys[e.RowIndex];
 var companyId = Utilities.GetCompanyId(); 
if (dataKey != null && companyId != null)
 { 
decimal cId = Convert.ToDecimal(companyId); 
decimal CarId = Convert.ToDecimal(dataKey.Value.ToString());
 var objContext = new CarShowRoomEntities();
 var showRoomData = objContext.tbl_Cars.SingleOrDefault(car => (car.CarId == CarId && car.CompanyId == cId));
 var allImages = objContext.tbl_Car_Image.Where(image => image.CarId == CarId).ToList();
 var largeImagePaths = new List(); // Complete paths for all full images to be deleted
 var thmbImagePaths = new List(); // Complete paths for all thumbnail images to be deleted
 foreach (var img in allImages)
 { 
largeImagePaths.Add(img.CarImagePath);
 thmbImagePaths.Add(img.CarThmb_ImagePath);
 objContext.DeleteObject(img);
 } 
objContext.DeleteObject(showRoomData);
 objContext.SaveChanges();
 try 
{
 foreach (var thmbImagePath in thmbImagePaths) 
{ 
var fi = new FileInfo(Server.MapPath(thmbImagePath));
 if (fi.Exists)
 { 
fi.Delete();
 }
 } 
foreach (var largeImagePath in largeImagePaths)
 { 
var fi = new FileInfo(Server.MapPath(largeImagePath));
 if (fi.Exists)
 { fi.Delete();
 } 
} 
} 
catch { } 
if (ViewState["SearchQuery"] != null) PopulateGridViewBasedOnQuery(ViewState["SearchQuery"].ToString()); else PopulateGridViewBasedOnQuery(); } }



因此,请提供任何解决方案,请指导我.



问候
TanzeelurRehman



So kindly if any solution available, kindly guide me.



Regards
TanzeelurRehman

推荐答案

其权限问题,您可以在web.config中添加身份模拟",IIS将使您的应用程序删除这些文件.

Its Permission Issue, You can add Identity Impersonation in your web.config and IIS will let your application deletes those files.

<identity impersonate="true">
          userName="domain\user" 
          password="password" /></identity>


这篇关于FileInfo不会从联机服务器中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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