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

Problema creando archivo .txt

Estas en el tema de Problema creando archivo .txt en el foro de .NET en Foros del Web. hola a todos, estoy creando un archivo .txt en con el siguiente codigo: Dim strStreamWriter As StreamWriter Dim strStreamW As Stream Dim FilePath As String ...
  #1 (permalink)  
Antiguo 06/02/2007, 14:59
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 4 meses
Puntos: 0
Pregunta Problema creando archivo .txt

hola a todos, estoy creando un archivo .txt en con el siguiente codigo:


Dim strStreamWriter As StreamWriter

Dim strStreamW As Stream

Dim FilePath As String = "Archivo.txt"

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim filename As String = Server.MapPath("~/mensaje/errores/" + FilePath)

strStreamW = File.OpenWrite(filename)

strStreamWriter = New StreamWriter(strStreamW, System.Text.Encoding.UTF8)



strStreamWriter.Close()

strStreamW.Close()

pero me sale el siguiente error cuando lo ejecuto:



Server Error in '/pca_z' Application.
--------------------------------------------------------------------------------

The process cannot access the file 'c:\inetpub\wwwroot\xyz\mensaje\errores\Archivo.tx t' because it is being used by another process.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.IOException: The process cannot access the file 'c:\inetpub\wwwroot\xyz\mensaje\errores\Archivo.tx t' because it is being used by another process.

Source Error:

Line 21: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Line 22: Dim filename As String = Server.MapPath("~/_administracion/deudas/errores/" + FilePath)
Line 23: strStreamW = File.OpenWrite(filename)
Line 24: strStreamWriter = New StreamWriter(strStreamW, System.Text.Encoding.UTF8)
Line 25:


alguna idea de como solucionar este problema?

se lo agradeceria mucho!
  #2 (permalink)  
Antiguo 06/02/2007, 17:02
Avatar de davidel  
Fecha de Ingreso: noviembre-2006
Mensajes: 17
Antigüedad: 17 años, 5 meses
Puntos: 0
Re: Problema creando archivo .txt

Por lo que dice el error el archivo está en uso. Revisa el código por si abres un objeto StreamWriter en algún otro sitio utilizando el mismo fichero y se te olvida cerrarlo.

Última edición por davidel; 06/02/2007 a las 17:10
  #3 (permalink)  
Antiguo 07/02/2007, 08:19
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 4 meses
Puntos: 0
Pregunta Re: Problema creando archivo .txt

gracias por responder, pero solo lo utilizo en ese codigo que envie para que me ayuden no lo uso en ningun otro lado.

El problema tiene que ser ahi, gracias de todoa modos.
  #4 (permalink)  
Antiguo 07/02/2007, 11:16
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: Problema creando archivo .txt

Intentalo de ésta forma:

Cita:
...
Dim filename As String = Server.MapPath("~/mensaje/errores/" + FilePath)
Dim fs As New FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)
Dim sw As New StreamWriter(fs, System.Text.Encoding.UTF8)
'sw.WriteLine("si quieres escribir algo")
sw.Flush()
fs.Close()
Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
  #5 (permalink)  
Antiguo 08/02/2007, 10:42
 
Fecha de Ingreso: enero-2007
Mensajes: 80
Antigüedad: 17 años, 4 meses
Puntos: 0
Re: Problema creando archivo .txt

gracias por respoder, ya solucione el problema de la siguiente forma:

Dim strStreamWriter As StreamWriter

Dim strStreamW As Stream

Dim FilePath As String = "Archivo.txt"

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim filename As String = Server.MapPath("~/mensaje/errores/" + FilePath)

try

strStreamW = File.OpenWrite(filename)

strStreamWriter = New StreamWriter(strStreamW, System.Text.Encoding.UTF8)

Catch ex As Exception
Me.Label3.Text = "Error" + ex.Message

Finally
strStreamWriter.Close()
strStreamW.Close()
End Try

Solo puse los .close dentro del finally y ya no me dice que no puedo usarlo ni nada de eso, gracias!!!
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 14:46.