Validate File after Upload completed

3 posts, 0 answers
  1. Kristian Kretschmer
    Kristian Kretschmer avatar
    9 posts
    Member since:
    Jun 2012

    Posted 08 Oct 2010 Link to this post

    Hello,

    i search for a method to validate the file, aber upload ist completed. Is a solution available to create something like a hashkey, before upload started and compare these hashkey with the uploaded file?

    Thank you.
  2. Kristian Kretschmer
    Kristian Kretschmer avatar
    9 posts
    Member since:
    Jun 2012

    Posted 08 Oct 2010 Link to this post

    Okay, here is my solution:

    i added a FileHashKey Parameter on the FileUploadStarting Event

     

     

     

    void RadUpload1_FileUploadStarting(object sender, Telerik.Windows.Controls.FileUploadStartingEventArgs e)
    {
      
    if (e.FileParameters.ContainsKey("FileHashKey"))
    {
    e.FileParameters["FileHashKey"] = MD5FileHash(e.SelectedFile.File);
    }
    else
    {
    e.FileParameters.Add("FileHashKey", MD5FileHash(e.SelectedFile.File));
    }
    }

    a function to create the hashkey
    i found a MD5CryptoServiceProvider implementation for silverlight here:
    http://www.markharris.net.au/blog/2008/10/23/md5cryptoserviceprovider-for-silverlight/

     

    private string MD5FileHash(FileInfo fiFile)
    {
            try
            {
                FileStream FileCheck = fiFile.OpenRead();
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                byte[] md5Hash = md5.ComputeHash(FileCheck);
                FileCheck.Close();
                FileCheck = null;
                string Berechnet = BitConverter.ToString(md5Hash).Replace("-", "").ToLower();
                md5Hash = null;
                return Berechnet;
            }
            catch (Exception)
            {
                return String.Empty;
            }
    }


    on serverside i compare the hashkeys in the 

    GetAssociatedData() method

     

     

     

     

     

       

    string HashKey = this.Request.Form["0_FileHashKey"];
    string localHashKey = String.Empty;
    if (HashKey != String.Empty)
    {
        localHashKey = MD5FileHash(MYSERVERFILEPATHHERE);
    }

     

     

    if (HashKey != localHashKey)
    {
    //FILE IS CORRUPT
    }

    i think, that's a good way to validate the file is complete.

     

  3. DevCraft banner
  4. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 11 Oct 2010 Link to this post

    Hi Kristian Kretschmer,

    Thank you for sharing your solution with us. Please let us know if we can assist you with anything else on the matter.

    Best wishes,
    Alex Fidanov
    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
Back to Top