elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  (solucionado) Problemas de acceso en un archivo de texto
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: (solucionado) Problemas de acceso en un archivo de texto  (Leído 1,790 veces)
Eleкtro
Ex-Staff
*
Conectado Conectado

Mensajes: 9.818



Ver Perfil
(solucionado) Problemas de acceso en un archivo de texto
« en: 22 Noviembre 2012, 11:30 am »

Tengo problemas al intentar escribir datos en un archivo de texto...

Cualquier ayuda, se agradece!


Las líneas del problema:
Código
  1.            If System.IO.File.Exists(Temp_file) = True Then System.IO.File.Delete(Temp_file)
  2.            System.IO.File.Create(Temp_file)
( Cualquiera de las dos líneas, si elimino una, me da el mismo error en la otra, pero el archivo si que me lo llega a crear (vacío) )

El error:
Código:
The process cannot access the file 'C:\Users\Administrador\AppData\Local\Temp\PlayList_temp.txt' because it is being used by another process.

El sub:
Código
  1.  Public Sub C1Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.  
  3.        If Not playerargs = Nothing Then
  4.  
  5.            Dim Str As String
  6.            Dim Pattern As String = ControlChars.Quote
  7.            Dim ArgsArray() As String
  8.            Dim Temp_file As String = System.IO.Path.GetTempPath & "\PlayList_temp.txt"
  9.            Dim objWriter As New System.IO.StreamWriter(Temp_file)
  10.  
  11.            Str = Replace(playerargs, " " & ControlChars.Quote, "")
  12.            ArgsArray = Split(Str, Pattern)
  13.  
  14.            If System.IO.File.Exists(Temp_file) = True Then System.IO.File.Delete(Temp_file)
  15.            System.IO.File.Create(Temp_file)
  16.  
  17.        For Each folder In ArgsArray
  18.            If Not folder = Nothing Then
  19.                Dim di As New IO.DirectoryInfo(folder)
  20.                Dim files As IO.FileInfo() = di.GetFiles("*")
  21.                    Dim file As IO.FileInfo
  22.  
  23.                For Each file In files
  24.                    ' command to writleline
  25.                    'Console.WriteLine("File Name: {0}", file.Name)
  26.                    'Console.WriteLine("File Full Name: {0}", file.FullName)
  27.                    objWriter.Write(file.FullName)
  28.                    objWriter.Close()
  29.                Next
  30.            End If
  31.            Next
  32.  
  33.        If randomize.Checked = True Then
  34.                RandomiseFile(Temp_file)
  35.        End If
  36.  
  37.        Process.Start(userSelectedPlayerFilePath, playerargs)
  38.        If autoclose.Checked = True Then
  39.            Me.Close()
  40.        End If
  41.        Else
  42.        MessageBox.Show("You must select at least one folder...", My.Settings.APPName)
  43.        End If
  44.    End Sub




EDITO: Ya está, solucionado:

Código
  1. ....
  2. If Not playerargs = Nothing Then
  3.    ....
  4.    Dim Temp_file As String = System.IO.Path.GetTempPath & "\PlayList_temp.txt"
  5.  
  6.    Using objWriter As New System.IO.StreamWriter(Temp_file, false)
  7.        For Each folder In ArgsArray
  8.            If Not folder = Nothing Then
  9.                Dim di As New IO.DirectoryInfo(folder)
  10.                Dim files As IO.FileInfo() = di.GetFiles("*")
  11.                Dim file As IO.FileInfo
  12.                For Each file In files
  13.                    ' command to writleline
  14.                    'Console.WriteLine("File Name: {0}", file.Name)
  15.                    'Console.WriteLine("File Full Name: {0}", file.FullName)
  16.                    objWriter.Write(file.FullName)
  17.                    ' objWriter.Close()
  18.                Next
  19.            End If
  20.        Next
  21.    End Using ' Flush, close and dispose the objWriter
  22.    ....


« Última modificación: 22 Noviembre 2012, 11:55 am por EleKtro H@cker » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
cifrar archivo de texto
Programación Visual Basic
XP. 4 2,108 Último mensaje 3 Junio 2006, 09:57 am
por Lambda
ARCHIVO DE TEXTO
Desarrollo Web
Esprinter 0 1,924 Último mensaje 1 Marzo 2011, 18:41 pm
por Esprinter
"Windows no tiene acceso al dispositivo ruta de acceso o archivo"
Análisis y Diseño de Malware
TheInfinityJoker 4 6,182 Último mensaje 3 Mayo 2011, 18:22 pm
por TheInfinityJoker
Texto a arrays [SOLUCIONADO]
Programación Visual Basic
rob1104 5 3,337 Último mensaje 6 Abril 2011, 17:28 pm
por rob1104
Alguien save como crear archivo php igual que el archivo de texto
Windows
BrokerJoker 6 6,707 Último mensaje 17 Mayo 2012, 02:47 am
por #!drvy
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines