IZWebFileManager

Advanced ASP.NET File Manager
Welcome to IZWebFileManager Sign in | Join | Help
in Search
The forum is moved to http://groups.google.com/group/izwebfilemanager
If you have any question, please post there. Thanks!

Delete Files

Last post 03-19-2010, 3:40 PM by nelson. 6 replies.
Sort Posts: Previous Next
  •  01-11-2010, 10:21 PM 445

    Delete Files

    Once i uploaded filed i'm unable to delete them. Even using FilesZilla i'm unable to delete these files. The Files i uploaded using fileszilla deletes without any problems. With filezille i recieve this error : "550 /wwwroot/Ump/images/Winter.jpg: Cannot delete file." and with IZ the following error: "The process cannot access the file 'C:\Domains\xxxxxx.co.za\wwwroot\ump\images\Winter(1).jpg' because it is being used by another process."
  •  03-09-2010, 7:18 PM 478 in reply to 445

    Re: Delete Files

    Does anyone have a solution to this?  I have done some more digging and apparently it's the thumbnail viewer that is locking them.  Switch to details/icons view, reload the page (i.e. by uploading a new file) and no more problems.  If you look at IZ.WebFileManager.ThumbnailHandler, you have:

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/jpeg";
        int num = 0x5c;
        string virtualPath = HttpUtility.UrlDecode(context.Request.Url.Query.Substring(1));
        Image image = Image.FromFile(context.Request.MapPath(virtualPath));
        if ((image.Width > num) || (image.Height > num))
        {
            int thumbWidth = (image.Width > image.Height) ? num : ((image.Width * num) / image.Height);
            int thumbHeight = (image.Width > image.Height) ? ((image.Height * num) / image.Width) : num;
            image = image.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero);
        }
        image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
    }
    

    I think the culprit is that there isn't a "using (Image image...)" or image.Dispose().  Will do some more testing.
  •  03-09-2010, 8:31 PM 479 in reply to 478

    Re: Delete Files

    Yup, that was it.  I modified it to dispose properly.  Since I didn't have the *.pfx file I couldn't sign the file, so I just created the class in my own project and modified the web.config to point to the new thumbnail handler (leaving the IZ assembly intact).

        /// <summary>
        /// Based on IZ.WebFileManager.ThumbnailHandler, but fixed disposing of Image.
        /// </summary>
        public class ThumbnailHandler : IHttpHandler
        {
            public bool IsReusable
            {
                get { return true; }
            }

            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "image/jpeg";
                int size = 92;

                string vPath = HttpUtility.UrlDecode(context.Request.Url.Query.Substring(1));
                string path = context.Request.MapPath(vPath);

                Image thumb = null;

                try
                {
                    using (Image original = Image.FromFile(path))
                    {
                        if (original.Width > size || original.Height > size)
                        {
                            int tw = original.Width > original.Height ? size : (original.Width * size) / original.Height;
                            int th = original.Width > original.Height ? (original.Height * size) / original.Width : size;

                            thumb = original.GetThumbnailImage(tw, th, null, IntPtr.Zero);
                        }
                        else
                        {
                            thumb = original;
                        }
                    }

                    thumb.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                }
                finally
                {
                    if (thumb != null)
                    {
                        thumb.Dispose();
                    }
                }
            }
        }

  •  03-09-2010, 8:46 PM 480 in reply to 479

    Re: Delete Files

    There is another problem.  If the file has parentheses, it will not render the thumbnail.  This commonly happens when you upload a file with the same name as an existing file.
  •  03-13-2010, 5:20 PM 481 in reply to 479

    Re: Delete Files

    I fixed it in the code:


            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "image/jpeg";
                int size = 92;

                string vPath = HttpUtility.UrlDecode(context.Request.Url.Query.Substring(1));
                string path = context.Request.MapPath(vPath);

                using (var original = Image.FromFile(path))
                {
                    if (original.Width > size || original.Height > size)
                    {
                        int tw = original.Width > original.Height ? size : (original.Width * size) / original.Height;
                        int th = original.Width > original.Height ? (original.Height * size) / original.Width : size;

                        using (var thumb = original.GetThumbnailImage(tw, th, null, IntPtr.Zero))
                        {
                            thumb.Save(context.Response.OutputStream, ImageFormat.Jpeg);

                        }
                    }
                    else
                    {
                        original.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                    }
                }

            }

    it will be in included the next release.

    Thanks.
  •  03-13-2010, 5:33 PM 482 in reply to 480

    Re: Delete Files

    nelson:
    There is another problem.  If the file has parentheses, it will not render the thumbnail.  This commonly happens when you upload a file with the same name as an existing file.


    this bug is fixed in the code.

    the fix will be available with next release.

    Thanks
  •  03-19-2010, 3:40 PM 483 in reply to 482

    Re: Delete Files

    Great, thank you.  I like your thumbnail solution better (two .Save()s but simpler).  I kept the original structure which didn't fit well with using(thumb).  I was going to check the parentheses issue eventually, but you beat me to it. :)
View as RSS news feed in XML
www.IZWebFileManager.com
izwebfilemanager@gmail.com