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

Using ashx handler to save in database

1 Answer 98 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Nelson
Top achievements
Rank 1
Nelson asked on 23 Aug 2011, 09:54 AM
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);
                            listaDesignacoes.Add(ResDesignacao);
                        }
 
 
                        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;
 
             
            domain.InsertAnexos(anexo);
 
        }
 
        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

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 26 Aug 2011, 10:27 AM
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.

Regards,
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 >>

Tags
Upload
Asked by
Nelson
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or