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>
<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" />
<anthem:Button ID="Button2" runat="server" Height="23px" OnClick="RemvFile_Click"
Text="Eliminar" Width="72px" />
</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.