MoveTo and file.Delete don't work for some time after upload

Last post 04-26-2011, 8:17 PM by cutechat. 11 replies.
Sort Posts: Previous Next
  •  05-31-2010, 4:27 AM 61447

    MoveTo and file.Delete don't work for some time after upload

    Some process seems to be locking the uploaded file, so we cannot move/delete the uploaded file. Is there a way around this?
     
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestAjax.ascx.cs" Inherits="TestAjax" %>
    <MagicAjax:AjaxPanel runat="server" ID="MagicAjax1" AjaxCallConnection="Asynchronous">
        <asp:Button runat="server" ID="UploaderInsertButton" Text="Upload file"  />
        <asp:Panel runat="server" ID="UploaderProgressPanel">
            <asp:Label ID="UploaderProgressTextLabel" runat="server" />
        </asp:Panel>
        
        <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertButtonID='UploaderInsertButton'
            ProgressCtrlID='UploaderProgressPanel' ProgressTextID='UploaderProgressTextLabel'
            OnFileUploaded="Uploader1_FileUploaded">
        </CuteWebUI:Uploader>
    </MagicAjax:AjaxPanel>
     

    public partial class TestAjax : UserControl
    {
        protected void Uploader1_FileUploaded(object sender, UploaderEventArgs file)
        {
            // Safe uploaded file
            string targetFileName = String.Format("{0}/{1}", Constants.FilePathUpload, file.FileName);
            file.MoveTo(Path.Combine(Constants.FilePathUpload, targetFileName));
        }
    }
  •  06-01-2010, 9:55 AM 61481 in reply to 61447

    Re: MoveTo and file.Delete don't work for some time after upload

    The code looks ok to me. Does it happen to all file uploading or happen to a particular file?

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-01-2010, 10:08 AM 61483 in reply to 61481

    Re: MoveTo and file.Delete don't work for some time after upload

    All files. Server is Windows 2003 / IIS 6, but we have similar problems with 2008 / IIS 7.

    Thanks
    Olaf
  •  06-01-2010, 10:21 AM 61485 in reply to 61483

    Re: MoveTo and file.Delete don't work for some time after upload

  •  06-01-2010, 10:44 AM 61486 in reply to 61485

    Re: MoveTo and file.Delete don't work for some time after upload

    Sorry, should've done this anyway. It's a System.IO Exception:
     
    In German:
    {"Der Prozess kann nicht auf die Datei \"C:\\Users\\Admin\\AppData\\Local\\Temp\\AjaxUploaderTemp\\persisted.77d9a535-ddaf-9c3b-a19b-1784e4789435.Unterschrift.tif.resx\" zugreifen, da sie von einem anderen Prozess verwendet wird."}
     
    The English version is "The process cannot access the file because it is being used by another process".
     
    The other process is either the local ASP.NET Development Server or, in a live environment, he IIS Worker Process. The error is thrown no matter if we use Flash or IFrame.

    I guess we miss something obvious because not many others have reported this problem so far.

    Thanks again.
  •  06-03-2010, 2:14 AM 61524 in reply to 61486

    Re: MoveTo and file.Delete don't work for some time after upload

    Hi,
     
    Can you try to upload a small file? 20K?
     
    Can you also try this appSettings in web.config ?
     
    <add key="CuteWebUI.AjaxUploader.UseAspNetStream" value="True" />
     
    If you still get same issues, I think you need check what processer lock the file.
     
    (anti-virus softeare, etc)
     
    Regards,
    Terry
  •  06-03-2010, 5:05 AM 61530 in reply to 61524

    Re: MoveTo and file.Delete don't work for some time after upload

    Hi Terry,
     
    1. it doesn't matter if the file is big or small
    2. the UseAspNetStream is already in the web.config
    3. this happens locally as well as on the production server, so there is no anti-virus software
    4. I already mentioned the process that locks the file: locally it's ASP.NET Development Server, in a live environment the IIS Worker Process.

    Somehow this has to do with a combination of the Ajax control that is used and the fact that they are located in .NET UserControls. In some scenarios it works. As soon as we see a pattern, we will post again.
     
    Thanks for now
    Olaf
     
  •  06-03-2010, 8:28 AM 61537 in reply to 61530

    Re: MoveTo and file.Delete don't work for some time after upload

    Olaf,
     
    Hope you can test it in a simple environment, not in your project.
     
    And then try the args.Delete();
     
    If it works for simple environment, that means there maybe something special which prevent the uploader release the temp file.
     
    If it's a bug of AjaxUploader , we will fix it.
     
     
    You can also test the UploadType property ,set it to IFrame/Silverlight/Flash and test again.
     
    If we get more details , we can fix it more quickly.
     
    Regards,
    Terry
  •  04-19-2011, 10:48 PM 67254 in reply to 61537

    Re: MoveTo and file.Delete don't work for some time after upload

    I am having the exact same issue.  I upload an image, and after I "MoveTo" the image becomes locked.  I can't upload a file with the same name because I can't delete it with code.  I try to delete it manually with windows explorer, and it's locked by the IIS Worker Process as explained above. 
     
    It works fine locally, it's just when I'm on the IIS 7  Windows 2008 server.  Is there something we can do to trouble shoot this?  This is very high priority for me. 
  •  04-26-2011, 1:10 AM 67326 in reply to 67254

    Re: MoveTo and file.Delete don't work for some time after upload

    Hi,
     
    As you said you can't access the locked image after 'MoveTo' ,
     
    So which file do you mean ? the uploader temp file ? or the new file in your folder ?
     
    Can you post more details ? exception stack trace or screen shot. Thanks.
     
    Regards,
    Terry
  •  04-26-2011, 2:22 AM 67327 in reply to 67326

    Re: MoveTo and file.Delete don't work for some time after upload

    Hi, I am facing the same problem.
     
    A summary of my code is to resize the image uploaded using Args.OpenStream() 
     
    There after I am unable to delete the temp file. Please advise. 
  •  04-26-2011, 8:17 PM 67336 in reply to 67327

    Re: MoveTo and file.Delete don't work for some time after upload

    Hi,
     
    You must dispose the stream after read it.
     
    using(Stream stream=args.OpenStream())
    {

    }
     
    or
     
    Stream stream=args.OpenStream();
    try
    {
    }
    finally
    {
        stream.Dispose();
    }
     
     
    Regards,
    Terry
     
View as RSS news feed in XML