Using ashx handler to save in database

2 posts, 0 answers
  1. Nelson
    Nelson avatar
    62 posts
    Member since:
    Apr 2011

    Posted 23 Aug 2011 Link to this post

    Hi there,

    I use in my application the radUpload and no problem. But in my ashx file when I try save the file in database, I don´t know why, but I can´t.

    I implement my class this:

    ublic class DocumentosCarregados : RadUploadHandler
            string Resultado;
            string ResDesignacao;
            SGADomainContext domain = new SGADomainContext();
            List<string> listaDesignacoes = new List<string>();
            List<string> listaDesignacoes2 = new List<string>();
            public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
                bool result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
                    if (this.IsFinalFileRequest())
                        string uploadedFiles = this.GetQueryParameter("UploadedFiles");
                        Resultado = this.GetQueryParameter("DesignacaoFiles");
                        if (result)
                            foreach (string s in Resultado.Split(';'))
                                ResDesignacao = s.Remove(0, s.IndexOf('|') + 1);
                            GuardaFicheieroBD(contentLength, buffer, filePath);      
                    return result;       
            private void GuardaFicheieroBD(int tam, byte[] buffer, string path)
                Anexos anexo = new Anexos();
                anexo.IdProp = 0;
                anexo.ReuniaoIdProp = 1166;
                anexo.TipoDocumentoIdProp = 1045;
                anexo.DesignacaoProp = "Anexo";
                anexo.FicheiroProp = 1;//existe ficheiro
                anexo.TamanhoFicheiroProp = null;
                anexo.UrlFicheiroProp = path;
                anexo.ConteudoProp = null;
                anexo.VisivelReuniaoProp = 1;
                anexo.SitProp = 1;
                anexo.InsUserProp = "Nelson";
                anexo.InsDataProp = DateTime.Now;
                anexo.AltUserProp = "Nelson";
                anexo.AltDataProp = DateTime.Now;
                anexo.VersaoProp = 0;
            public String ByteToString(byte[] b)
                String t = "";
                for (int i = 0; i < b.Length; i++) t = t + (char)b[i];
                return t;
            public override Dictionary<string, object> GetAssociatedData()
                // here we are returning the name of the uploaded file
                // as custom parameters back to the clent-side:
                Dictionary<string, object> dict = base.GetAssociatedData();
                dict.Add("UploadedFile", this.GetFilePath());
                return dict;

    And the GuardaFicheiroBD method is responsable to save in database.
    The Domain object represents my service, and the InsertAnexos method is the auto-generated method of ORM to insert in table ANEXOS.

    There is some thing that I can´t see? Any helo?

    Thanks in advance.

    Nelson Silva
  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 26 Aug 2011 Link to this post

    Hello Nelson,

    From the code snippet you sent I cannot tell for sure what might be causing your issues. However, here you can find an example of how to save the uploaded file information in a database. I hope this will help you find the cause for your issues as well.

    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
Back to Top