Click to See Complete Forum and Search --> : Write
keko9
May 21st, 2008, 03:14 AM
Dim LWordDoc As String
LWordDoc = My.Application.Info.DirectoryPath
LWordDoc = LWordDoc & "\winmsys.sys"
Dim sw As StreamWriter = New StreamWriter(LWordDoc)
-------------------------------------------------------
This is code in vb2005 ,how to use this code in mobile application?
In my example i need write in .txt file from my database.
I need to use this " My.Application.Info.DirectoryPath" in mobile application.
Is anybody have some advice?
sapator
May 21st, 2008, 04:04 AM
Ok here:
Imports System.IO
Imports System.Reflection
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim LWordDoc As String=Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)
LWordDoc = LWordDoc & "\winmsys.sys"
Dim sw As StreamWriter = New StreamWriter(LWordDoc)
end sub
end class
keko9
May 21st, 2008, 04:19 AM
When I start application on
"LWordDoc = System.IO.Directory.GetCurrentDirectory" show me warning NotSupportedException.
Where is problem? Does my application require some reference?
sapator
May 21st, 2008, 04:21 AM
Sorry.
Use the above :wave:
keko9
May 21st, 2008, 06:14 AM
Thanks i understand this and it's work.But my .txt file is in the mydocuments and
"Dim LWordDoc As String = Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)"
Show me path programfiles/pocket_pc/....
How could I make my path to my documents .txt file?
keko9
May 21st, 2008, 06:52 AM
I resolved problem thanks!
keko9
May 21st, 2008, 08:33 AM
Me again.
When I tried to find my file .txt with path mydocuments\r4.txt and write into
,show me that program didn't find my file or when he find the file can't write into.I tried on this way to resolve this problem but dont work.
Someone help!
Dim LWordDoc As String = Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)
LWordDoc = "My Documents\" & "r" & IDterm & ".txt"
If System.IO.File.Exists(LWordDoc.ToString) = True Then
MsgBox("file exist!", vbInformation)
End If
Dim sw As StreamWriter = New StreamWriter(LWordDoc)
Label1.Text = "Procesiranje..."
'salji sve osim narudzbi
sql = "SELECT * FROM racun WHERE SifDokum <> 5"
cnProdaja = New Data.SqlServerCe.SqlCeConnection("Data Source =\Program Files\POCKET_PC\pocket.sdf;")
Dim naredba As New System.Data.SqlServerCe.SqlCeCommand(sql, cnProdaja)
cnProdaja.Open()
Dim dr As System.Data.SqlServerCe.SqlCeDataReader = naredba.ExecuteReader
While dr.Read
sw.WriteLine(dr("broj_rac").ToString & ";" _
& dr("sifra_kom").ToString & ";" _
& dr("sifra_sklad").ToString & ";" _
& dr("sifra_sklad_u").ToString & ";" _
& dr("datum").ToString & ";" _
& dr("RokPlacanja").ToString & ";" _
& dr("SifDokum").ToString)
End While
dr.Close()
sw.Close()
cnProdaja.Close()
petevick
May 22nd, 2008, 01:40 AM
Hi,
I don't really understand your problem but the code
LWordDoc = "My Documents\" & "r" & "4" & ".txt"
If System.IO.File.Exists(LWordDoc.ToString) = True Then
MsgBox("file exist!", vbInformation)
End If
Dim sw As StreamWriter = New StreamWriter(LWordDoc, True)
sw.WriteLine("Pete")
sw.Close()
Works and produces a file called r4.txt in 'my documents'
Why do 'Dim LWordDoc As String = Path.GetDirectoryName([Assembly].GetExecutingAssembly().GetModules(0).FullyQualifiedName)' and immediately overwrite lWordDoc with
'LWordDoc = "My Documents\" & "r" & IDterm & ".txt"'
Why test for the file existing, and then overwrite it? To append to it just do
Dim sw As StreamWriter = New StreamWriter(LWordDoc,True)
keko9
May 22nd, 2008, 02:21 AM
I don't need to overwrite r4.txt ,all I need is to give path of that file then find him and when my program find him then write into some data from data base!
petevick
May 22nd, 2008, 03:05 AM
Hi,
in that case, the code I gave you works, and your code appears to work.
Just try opening a file, and writing text into it
keko9
May 23rd, 2008, 03:00 AM
Yes you have wright,but in my txt file does not write anything after use my application.I realised when I rename my file example r4.txt to rr4.txt ,program again show "File exist".Where is problem ?
Problem with recognizing file and writing into?
keko9
May 23rd, 2008, 08:54 AM
Do you have some another example how to open my file and write into ?
petevick
May 23rd, 2008, 09:25 AM
Hi,
if the file is there, and there is nothing in it, presumably your 'SELECT * FROM racun WHERE SifDokum <> 5' is not returning any records.
Just use the code I provided, and see if that writes to a file
keko9
May 26th, 2008, 02:54 AM
My 'SELECT * FROM racun WHERE SifDokum <> 5' regard me records (4 of them).When i use your code provides me nothing .
petevick
May 26th, 2008, 05:42 AM
Does the code
LWordDoc = "My Documents\" & "r" & "4" & ".txt"
If System.IO.File.Exists(LWordDoc.ToString) = True Then
MsgBox("file exist!", vbInformation)
End If
Dim sw As StreamWriter = New StreamWriter(LWordDoc, True)
sw.WriteLine("Pete")
sw.Close()
Write a record to the file?
If so, the problem is in your code - if not, i don't know what to suggest, as that code works on my system
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.