ASP.NET - error al crear archivo.txt

 
Vista:

error al crear archivo.txt

Publicado por Liz (3 intervenciones) el 06/02/2007 21:57:22
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.txt' 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.txt' 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!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 56
Bronce
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

RE:error al crear archivo.txt

Publicado por Yamil Bracho (1136 intervenciones) el 07/02/2007 14:58:52
Creo que StreamWriter trata de abrir el archivo cuando ya File.Open lo ha hecho.
Usa solo StreamWriter
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:error al crear archivo.txt

Publicado por Liz (3 intervenciones) el 07/02/2007 15:06:00
gracias, por responder pero de que manera con el codigo que envie podria usar solo StreamWriter sin usar File.Open.

Gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 56
Bronce
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

RE:error al crear archivo.txt

Publicado por Yamil Bracho (1136 intervenciones) el 07/02/2007 20:56:42
Haces:

StreamWriter sw = new StreamWriter(filename);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar