El Comité recomienda que el Estado Parte adopte todas las medidas necesarias para garantizar la igualdad entre los géneros en todos los niveles de vida, incluida la educación. (Español (Spanish))

El Comité recomienda que el Estado Parte adopte todas las medidas necesarias para garantizar la igualdad entre los géneros en todos los niveles de vida, incluida la educación.

Sunday, 29 February 2004

//

2 minute read

ASP.NET tiene un problema con los descargas de archivos...basicamente si utiliza Respuesta el fichero entero es bufferado en memoria antes de su ' descargado - esto NO es bueno para Scalability. Para roundar ese problema, aquíM SK2 es algún código que podría ser usado para el archivo Descargar - parece el archivo descargado, sólo descargando fragmentos en un momentoM SK2 También verifica que el cliente está conectado antes de enviar el siguiente chunk...


private void DownloadFile(Guid itemId)
        {
            //Where to start in the file
            long startPos = 0; 
            //How big a chunk to download in each iteration
            long chunkSize = 20480;
            //Use the id to retreive the resource files details
            using(SqlDataReader reader=SqlExtra.ExecuteReader("GetResource", itemId))
            {
                try
                {
                    if(reader.Read())
                    {
                        //Get the file details we need to save a copy to the client
                        string fileExtension=reader["FileTypeExtension"].ToString();
                        string fileNameClient=reader["FileName"].ToString();
                        string fileNameServer=Server.MapPath(string.Format(@"Uploads/{0}{1}", itemId.ToString(),  fileExtension));
                        FileInfo file=new FileInfo(fileNameServer);    
                        //Only proceed with the download if the file physically exists
                        if (file.Exists)
                        {
                            
                            //Setup the Response object to allow file downloads
                            Response.Clear();
                            Response.ContentType = "application/octet-stream";
                            //Attach the file to the response stream.
                            Response.AddHeader("Content-Disposition", string.Format("{0}{1}", "attachment; filename=", fileNameClient));
                            Response.AddHeader("Content-Length",file.Length.ToString());
                            long fileSize = file.Length;
                            try
                            {
                                while(startPos < file.Length)
                                {
                                    if(Response.IsClientConnected)
                                    {
                                        //write the file to the client
                                        if(startPos + chunkSize > fileSize)
                                        {
                                            chunkSize = fileSize - startPos;
                                        }
                                        Response.WriteFile(fileNameServer,startPos,chunkSize);    
                                        Response.Flush();
                                        startPos += chunkSize;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                
                            }
                            catch(Exception ex)
                            {
                                ExceptionManager.Publish(ex);
                            }
                            Response.End();
                        }
                        else
                        {
                            //display an error message
                            StatusMessage.Text=fileNameClient;
                        }
                    
                    }
                }
                catch(Exception ex)
                {
                    if(ex.GetType() != typeof(System.Threading.ThreadAbortException))
                    {
                        ExceptionManager.Publish(ex);
                    }
                }
            }
        }

Espero que le resulte útil... perdón por la formatación...se parece que esta página no es El Comité recomienda al Estado Parte que adopte todas las medidas necesarias para garantizar la igualdad entre los géneros y el empoderamiento de la mujer.

Finding related posts...
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.