zero byte file after upload completes

2 posts, 0 answers
  1. Ronnie
    Ronnie avatar
    3 posts
    Member since:
    Aug 2011

    Posted 11 Oct 2011 Link to this post

    I'm using the silverlight RadUpload control. I have no problems uploading files UNTIL I try to change the name of the uploaded file.

    My upload scenario has these 2 requirements:

    1. Save the file outside of the web site directory structure
    2. Ignore the actual filename and save the uploaded file with a new GUID as the filename


    Here is my UploadHandler:

        public class BatchUpload : RadUploadHandler

        {

            public override string GetTargetFolder()

            {

                string targetFolder = ConfigurationManager.AppSettings["BatchDataDirectory"];

                return targetFolder;

            }

            public override string GetFileName()

            {

                string filename = GetQueryParameter("sysFilename");

                return filename;

            }

        }



    And here is the Silverlight code:

    private void RadUpload_FileUploadStarting(object sender, FileUploadStartingEventArgs e)

    {

        e.FileParameters["sysFilename"] = (_sysFilename = Guid.NewGuid().ToString());

    }



    During the upload I can see the file in Windows Explorer and watch the file size increase, but when the upload completes, the file is empty and has a size of zero bytes
    .

    See: http://youtu.be/-4g2c4xiHKc

  2. Ronnie
    Ronnie avatar
    3 posts
    Member since:
    Aug 2011

    Posted 11 Oct 2011 Link to this post

    Disregard this problem. There was some obscure, old code that was writing an empty string over the file after upload completed. Also, here's a more concise way to rename the file on the server side:

      public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)

            {

                string dir = ConfigurationManager.AppSettings["UploadDir"];

                string filename = GetQueryParameter("NewFilename");

                string newFilepath = Path.Combine(dir, filename);

                return base.SaveChunkData(newFilepath, position, buffer, contentLength, out savedBytes);

            }

  3. DevCraft banner
Back to Top