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

zero length file after upload

1 Answer 68 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Karl Wilkens
Top achievements
Rank 1
Karl Wilkens asked on 05 Mar 2010, 08:30 PM
Hi, I am using upload and the gridbinary column pretty much right out of the samples found elsewhere on this site. I am not even bothering with upload progress bars, etc. and there is no ajax involved. I am using  Q3 2009, and the Uploaded file name is present, but the length is zero - I am trying to read into a byte array but there is nothing to read into. Here is a code frag - if anyone knows what I am doing wrong here, please  let me know.

Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
                    Dim upload As RadUpload = DirectCast(editItem.EditManager.GetColumnEditor("Upload"), GridBinaryImageColumnEditor).RadUploadControl
                    Dim MyUploadedFile As Telerik.Web.UI.UploadedFile = upload.UploadedFiles(0)

                    Dim MyFileName As String = MyUploadedFile.FileName ' this evaluates to the file I am uploading
                    Dim fs As System.IO.Stream = MyUploadedFile.InputStream ' fs.length is always zero.

                    Dim picture As Byte() = New Byte(fs.Length - 1) {}
                    fs.Read(picture, 0, fs.Length - 1)
                    fs.Close()

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 09 Mar 2010, 05:07 PM
Hi Karl Wilkens,

Which RadGrid event do you use to grab the uploaded files? I tried hooking on the UpdateCommand event and I was able to obtain the uploaded file with correct InputStream length.

Sample code:

Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
         If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
             Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
             Dim upload As RadUpload = DirectCast(editItem.EditManager.GetColumnEditor("Upload"), GridBinaryImageColumnEditor).RadUploadControl
             Dim MyUploadedFile As Telerik.Web.UI.UploadedFile = upload.UploadedFiles(0)
 
             Dim MyFileName As String = MyUploadedFile.FileName ' this evaluates to the file I am uploading
             Dim fs As System.IO.Stream = MyUploadedFile.InputStream ' fs.length is always zero.
 
             Dim picture As Byte() = New Byte(fs.Length - 1) {}
             fs.Read(picture, 0, fs.Length - 1)
             fs.Close()
 
         End If
     End Sub

Can you try attaching to the same event. Is the uploaded file still with zero length?

Sincerely yours,
Genady Sergeev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Upload (Obsolete)
Asked by
Karl Wilkens
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or