Foros del Web » Programación para mayores de 30 ;) » .NET »

Subir ficheros

Estas en el tema de Subir ficheros en el foro de .NET en Foros del Web. Hola Estoy intentando subir ficheros al servidor. Pero me da el siguiente error: Error añadiendo el comentario Error salvando el fichero C:\temp\ System.ObjectDisposedException: Cannot access ...
  #1 (permalink)  
Antiguo 02/08/2007, 10:57
 
Fecha de Ingreso: junio-2007
Mensajes: 380
Antigüedad: 16 años, 10 meses
Puntos: 0
Subir ficheros

Hola
Estoy intentando subir ficheros al servidor. Pero me da el siguiente error:


Error añadiendo el comentario Error salvando el fichero C:\temp\
System.ObjectDisposedException: Cannot access a closed file. at System.IO.__Error.FileNotOpen() at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin) at System.Web.HttpRawUploadedContent.TempFile.GetByte s(Int32 offset, Int32 length, Byte[] buffer, Int32 bufferOffset) at System.Web.HttpRawUploadedContent.WriteBytes(Int32 offset, Int32 length, Stream stream) at System.Web.HttpInputStream.WriteTo(Stream s) at System.Web.HttpPostedFile.SaveAs(String filename) at ResultadoAltaIncidenciaCliente.Upload_ServerClick( String userId, ArrayList hif)
Datos de la incidencia

EL directorio existe y tengo permisos de escritura en el servidor. El código que uso es:

<input id="FindFile" runat="server" size="26" type="file" /><br />
</td>
<td align="left" >
<anthem:Button ID="Button3" runat="server" Text="Añadir comentarios y archivos" OnClick="ButtonComentario_Click" Width="279px" />
</td>
</tr>

<tr>
<td colspan="2" align="left" >
<anthem:Label ID="Label3" runat="server" Font-Bold="True" Text="Archivos:"></anthem:Label>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
<anthem:ListBox ID="ListBox1" runat="server" Font-Size="XX-Small" Height="45px"
Width="575px" ToolTip="Archivos a adjuntar">
</anthem:ListBox>
<br />
</td>
</tr>
<tr>
<td colspan="2" align="center" >
<anthem:Button ID="Button1" runat="server" Height="23px" OnClick="AddFile_Click"
Text="Añadir" Width="72px" />
&nbsp;


<anthem:Button ID="Button2" runat="server" Height="23px" OnClick="RemvFile_Click"
Text="Eliminar" Width="72px" />&nbsp;
</td>
</tr>


Y en sl codebehind:

/// <summary>
/// Upload_ServerClick is the server side script that will upload the files to the web server
/// by looping through the files in the listbox.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static IList Upload_ServerClick(string userId, ArrayList hif)
{
string baseLocation = "C:\\temp\\";
string status = "";
ArrayList documentos = new ArrayList();


if ((hif.Count == 0))
{
return new ArrayList();
}
else
{
//recorremos cada uno de los ficheros y los añadimos
foreach (System.Web.UI.HtmlControls.HtmlInputFile HIF in hif)
{
try
{
string fn = System.IO.Path.GetFileName(HIF.PostedFile.FileName );
string contentType = HIF.PostedFile.ContentType;
HIF.PostedFile.SaveAs(baseLocation + fn);
long longitud = HIF.PostedFile.InputStream.Length;
byte[] fichero = new byte[longitud];
HIF.PostedFile.InputStream.Read(fichero, 0, (int)longitud);
Documento iD = new Documento();
iD.ContentType = contentType;
iD.Contenido = fichero;
iD.Fecha = DateTime.Now;
iD.IdUsuario = userId;
documentos.Add(iD);
System.IO.File.Delete(baseLocation + fn);
}
catch (Exception err)
{
throw new Exception("Error salvando el fichero " + baseLocation + "<br>" + err.ToString());
}
}


hif.Clear();

return documentos;
}
}

En el Visual Studio funciona pero en un servidor aparte. Alguien me ha comentado que no use un input. Cual es el máximo tamaño que puedo subir.
  #2 (permalink)  
Antiguo 02/08/2007, 23:12
Avatar de Shiryu_Libra
Colaborador
 
Fecha de Ingreso: febrero-2007
Ubicación: Cantando "Screenager" en "Kirafa Kaput"
Mensajes: 3.614
Antigüedad: 17 años, 2 meses
Puntos: 88
Re: Subir ficheros

creo que en NET, podran contestarte mejor, suerte
__________________
"Eres parte del problema, parte de la solucion o parte del paisaje"
Un Saludo desde Desierto de Altar, Sonora, MX.
Shiryu_libra
  #3 (permalink)  
Antiguo 31/08/2007, 11:29
 
Fecha de Ingreso: junio-2007
Mensajes: 380
Antigüedad: 16 años, 10 meses
Puntos: 0
Re: Subir ficheros

Mi duda sigue estando activa
  #4 (permalink)  
Antiguo 01/09/2007, 10:19
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Re: Subir ficheros

Cita:
Cual es el máximo tamaño que puedo subir.
El tamaño lo puedes definir en el web.config

http://www.forosdelweb.com/showthrea...e=2#post848328

Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:11.