Results 1 to 15 of 15

Thread: Write

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Write

    Code:
       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?

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Write

    Ok here:

    Code:
    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
    Last edited by sapator; May 21st, 2008 at 04:18 AM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    When I start application on
    "LWordDoc = System.IO.Directory.GetCurrentDirectory" show me warning NotSupportedException.
    Where is problem? Does my application require some reference?

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Write

    Sorry.
    Use the above

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    Thanks i understand this and it's work.But my .txt file is in the mydocuments and
    Code:
    "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?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Resolved Re: Write

    I resolved problem thanks!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    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!

    Code:
    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()

  8. #8
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Write

    Hi,
    I don't really understand your problem but the code

    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)
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    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!

  10. #10
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Write

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    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?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    Do you have some another example how to open my file and write into ?

  13. #13
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Write

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Oct 2007
    Posts
    192

    Re: Write

    My 'SELECT * FROM racun WHERE SifDokum <> 5' regard me records (4 of them).When i use your code provides me nothing .

  15. #15
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Write

    Does the code
    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width