uploader in web control

Last post 05-29-2008, 5:37 AM by cutechat. 1 replies.
Sort Posts: Previous Next
  •  05-23-2008, 5:32 PM 40733

    uploader in web control

    Hi,
     
    I'm having a problem when I try adding the uploader into my composite web control. All i'm doing is this..
     
    class ... 
    {
         private CuteWebUI.Uploader _FileUploadControl;
     
         protected override void CreateChildControls()
         {
             base.CreateChildControls();

             //new upload control
             if (!DisableUpload)
             {
                _FileUploadControl = new CuteWebUI.Uploader();
                _FileUploadControl.FileUploaded += new CuteWebUI.UploaderEventHandler(_FileUploadControl_FileUploaded);
                Controls.Add(_FileUploadControl);
             }
        }
     
    void _FileUploadControl_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
          {
         
                try
                {
                   byte[] data = new byte[args.FileSize];
                   args.OpenStream().Read(data, 0, data.Length);

                   AFSFile file = new AFSFile(data, "FolderName", "", args.FileName)
                   file.Save();

    ...
     
         ...
    }
     
     
    The file data is uploaded successfully to the database using the code in the FileUploaded event. But for some reason I always get this error right after...
     
    The process cannot access the file 'FILE PATH' because it is being used by another process.
     
    Can anyone figure out a reason why?
     
    Thanks! :)

    Regards,

    Moe
  •  05-29-2008, 5:37 AM 40880 in reply to 40733

    Re: uploader in web control

    Hi,
     
    You need dispose the stream when you opened it.
     
    byte[] data = new byte[args.FileSize];
    using(Stream stream=args.OpenStream())
    {
        stream.Read(data,0,data.Length);
    }
    AFSFile file = new AFSFile(data, "FolderName", "", args.FileName)
    file.Save();
     
    Regards , Terry.
View as RSS news feed in XML