Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/11/2014, 15:07
Avatar de ras_chalo
ras_chalo
 
Fecha de Ingreso: junio-2010
Mensajes: 369
Antigüedad: 13 años, 11 meses
Puntos: 6
Pregunta error: un proceso ya ocupa dicho archivo. cmo lo soluciono?

hola a todos, tengon un problema al leer archivos txt,
el tema es que no logro dar con la solucion a mi problema:

estoy intentando recorrer las filas o lineas de un archivo .txt y el tema es que necesito instanciar dos veces mi "path", en donde me arroja error que ya un proceso esta ocupando mi "archivo.txt" (al iniciar el StreamReader) y luego ocupar el File.Delete(path)... no sé como darle solución a esto...

path = "archivo.txt"
Código C++:
Ver original
  1. string path = "archivo.txt"
  2.                 using (StreamReader reader = new StreamReader(path))
  3.                 {
  4.                    
  5.                     line = reader.ReadLine();      
  6.                     while (line != null)
  7.                     {
  8.                          
  9.                                                     string[] contenidoActual = File.ReadAllLines(path);
  10.                                                     File.Delete(path);
  11.                                                     if (contenidoActual.Length > 1)
  12.                                                         using (StreamWriter writer = File.CreateText(path))
  13.                                                         {
  14.                                                             for (int u = 1; u < contenidoActual.Length; u++)
  15.                                                             {
  16.                                                                 writer.WriteLine(contenidoActual[u]);
  17.                                                             }
  18.                                                         }
  19.                       line = reader.ReadLine();        
  20.                      }

cualquier idea es bien recibida, muchas gracias por su tiempo
Estaré atento a sus respuestas!,
Saludos!