删除服务器上的文件时出错 [英] Error while delete file on server

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

问题描述

我想删除文件,但发生错误,请帮助我.
============================
进程无法访问文件``D:\ My Project \ AzadUniv \ New \ 12 \ GUI \ Upload \ NewsImage \ 5564868769930125853-Image'',因为它正在被另一个进程使用.
============================


I want delete a file but an error occured please help me.
==============================
The process cannot access the file ''D:\My Project\AzadUniv\New\12\GUI\Upload\NewsImage\5564868769930125853-Image'' because it is being used by another process.
==============================


string ImagePath = Server.MapPath(".")+"\\Upload\\NewsImage\\" + Utility.GenerateGUID() + "-Image";
            if (fuImage.PostedFile != null)
            {
                fuImage.PostedFile.SaveAs(ImagePath);
                fuImage.Dispose();
                string d = Utility.GetThumbnailImage(ImagePath, 100, 100,true);

            }



  public static string GetThumbnailImage(string path,int x,int y,bool DeleteAfterSave)
        {

                // Create the in-memory bitmap where you will draw the image.
                Bitmap image = new Bitmap(x, y);
                Graphics g = Graphics.FromImage(image);

                // Load the file data.
                System.Drawing.Image thumbnail =
                System.Drawing.Image.FromFile(path);

                // Draw the thumbnail.
                g.DrawImage(thumbnail, 0, 0, x, y);

                // Render the image.
                string NewPath = path +"-small.jpg";
               image.Save(NewPath, ImageFormat.Jpeg);
                
                g.Dispose();
                image.Dispose();
                if (DeleteAfterSave == true)
                {
                    System.IO.File.Delete(path);
                }
                return path;
            }

推荐答案

您正试图删除在 thumbnail 对象中读取的文件.也许如果您丢弃了缩略图对象,则文件资源将被释放.
You are attempting to delete the file that was read in within the thumbnail object. Perhaps if you disposed of the thumbnail object, the file resource would be released.


这篇关于删除服务器上的文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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