0% found this document useful (0 votes)
3 views

codigo2

Código en Visual

Uploaded by

Valeria Mercado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

codigo2

Código en Visual

Uploaded by

Valeria Mercado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

If DataGridView1.

RowCount = 0 Then
MessageBox.Show("the datagridview is emptly")
Else
If Directory.Exists("C:\Foldertxt") = False Then
Directory.CreateDirectory("C:\Foldertxt")
End If
Dim sFile As String = "C:\Foldertxt\file.txt"

Dim count As Integer = 1

Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sFile)


Dim extension As String = Path.GetExtension(sFile)
Dim path__1 As String = Path.GetDirectoryName(sFile)
Dim newFullPath As String = sFile

While File.Exists(newFullPath)
Dim tempFileName As String = String.Format("{0}({1})", fileNameOnly,
System.Math.Max(System.Threading.Interlocked.Increment(count),count - 1))
newFullPath = Path.Combine(path__1, tempFileName & extension)
End While

Using f As New IO.StreamWriter(newFullPath, True)

Dim col As String = ""

Dim row As String = ""


Dim i As Integer = 0
For Each r As DataGridViewRow In DataGridView1.Rows
For Each c As DataGridViewColumn In DataGridView1.Columns
row = row & "'" &
Convert.ToString(r.Cells(c.HeaderText).Value) & "' "
Next
If i < DataGridView1.Rows.Count - 1 Then row &=
Environment.NewLine
Next

f.WriteLine(row)
MessageBox.Show("file created")
End Using
End If

You might also like