This is a migrated thread and some comments may be shown as answers.

ProcessStream doesn't fire on all files

3 Answers 28 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Developer
Top achievements
Rank 1
Developer asked on 02 Jan 2012, 10:24 AM
Silverlight code:

<telerik:RadUpload Grid.Column="1"
                    x:Name="RadUpload" Margin="8 0 8 0"
                    Filter="PDF Files (*.pdf)|*.pdf|Excel Files (*.xls)|*.xls|All Files(*.*)|*.*"
                    FilterIndex="0" MaxFileCount="50"   
                    AllowDrop="true" Width="340"
                    IsAutomaticUpload="false"
                    OverwriteExistingFiles="True"
                    UploadServiceUrl="UploaderHandler.ashx"
                    TargetFolder="~/Content/Uploader/"
                    HorizontalAlignment="Left"
                    MaxFileSize="2147483647" MaxUploadSize="2147483647" 
                    FileUploadStarting="RadUpload_FileUploadStarting"/>

Handler code:

public class UploaderHandler : RadUploadHandler
    {
        private class FileDesc
        {
            public string FilePath { get; set; }           
            public int LanguageId { get; set; }
            public int AdministratorId { get; set; }
            public int CategoryId { get; set; }
        }
 
        private static List<FileDesc> _fileDescs = new List<FileDesc>();
 
        public override void ProcessStream()
        {
            base.ProcessStream();
 
            if (_fileDescs.Where(fd => fd.FilePath == GetFilePath()).Count() == 0)
            {
                _fileDescs.Add(new FileDesc()
                {
                    FilePath = GetFilePath(),
                    AdministratorId = Convert.ToInt32(GetQueryParameter("AdministratorId")),
                    LanguageId = Convert.ToInt32(GetQueryParameter("LanguageId")),
                    CategoryId = Convert.ToInt32(GetQueryParameter("CategoryId"))
                });
            }
 
            if (IsFinalUploadRequest())
            {
              [some code]
            }
     }
}

Uploader sending files to server with some additional information. Silverlight part works good - all data being sended.

The problem is in handler part. In method ProcessStream either IsFinalFileRequest() or just simple collection requests (like in my code) doesn't work. Some of file never got "called" via processStream method. What is strange the file is in uploader temporary folder - but it's locked  for delete and manipulation. So seems like some file object isn't closed.

Any advice. How to properly collect all sended files?

Silverlight version: 2011.3.1220.1040
Server side dll version: 2011.3.1116.35

regards

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 05 Jan 2012, 10:51 AM
Hi Developer,

 Could you please elaborate more on your scenario? How do you try to open/interact with the file in the ProcessStream? Do you encounter some exceptions when trying to open the uploaded file? How do you detect that it is locked? Is it possible for you to try the SaveChunkData method instead and let us know if it is suitable for you? Thank you in advance for your cooperation.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Developer
Top achievements
Rank 1
answered on 05 Jan 2012, 11:54 AM
Hey

Seems I wasn't clear enough. My goal is to catch all uploaded files in ProcessStream(), because I need to to some additional work on them after they uploaded to my temp directory.
While ProcessStream() I'm trying to collect all uploaded file names; then when IsFinalUploadRequest() returns "true" I want to execute my post upload code. But the problem is that in ProcessStream not all files are notified. Is that clear now?

regards
0
Alex Fidanov
Telerik team
answered on 10 Jan 2012, 10:56 AM
Hi,

You should be able to access the file stream of the uploaded file in the SaveChunkData method, after calling the base implementation. Below, is a sample source code that you can use to manipulate all of the uploaded files:

public class UploadHandler : RadUploadHandler
    {
        private static List<string> FileNames = new List<string>();
        public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
        {
            var result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
 
            if (!FileNames.Contains(filePath))
                FileNames.Add(filePath);
            if (this.IsFinalUploadRequest())
            {
                foreach (var fileName in FileNames)
                {
                    Stream fileStream = null;
                    try
                    {
                        fileStream = File.Open(fileName, FileMode.Open);
                        System.Diagnostics.Debug.WriteLine("Opening file " + fileName);
                    }
                    catch
                    {
                        System.Diagnostics.Debug.WriteLine("Open file exception");
                    }
                    finally
                    {
                        if (fileStream != null)
                            fileStream.Close();
                    }
                }
 
                FileNames.Clear();
            }
 
            return result;
        }
    }


Regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Upload
Asked by
Developer
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Developer
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or