none
wrong file handling using standard folder method RRS feed

  • Question

  • THIS IS A NEW PROBLEM!

    the current app has been running for abt a year and today I had to change some of its functionality, but not the setup of the log file. I use standard methods to display the folder system an let the user select which folder to put the log file. This has been used in a number of prgrams over the last years and worked. But today:

    - when chreating the file path and name, the global variable fpath1 contains, according to the VB2010 IDE the correctly selected file path and file name. BUT when Windows try to open this file, it ADDS the whole path from root doen to the VB2010 folder in fron of the correct filepath and name, which makes it a completely useless and wrong combination, what Windows of course cannot open.

    In the example I have two files, fpath1 and pfath2 that only differs in content and that fpath2 has the additional "_lbl" in the file name. This has worked a week ago, but not any longer.

    Some changes in Windows7 must have caused this. How to get around this??????

     Form6.ShowDialog()
    
    
                ' Declare a variable named theFolderBrowser of type FolderBrowserDialog.
                Dim theFolderBrowser As New FolderBrowserDialog
                ' Set theFolderBrowser object's Description property to
                '   give the user instructions.
                theFolderBrowser.Description = "Please select a folder to save the file."
                ' Set theFolderBrowser object's ShowNewFolder property to false when
                '   the a FolderBrowserDialog is to be used only for selecting an existing folder.
                theFolderBrowser.ShowNewFolderButton = False
                ' Optionally set the RootFolder and SelectedPath properties to
                '   control which folder will be selected when browsing begins
                '   and to make it the selected folder.
                ' For this example start browsing in the Desktop folder.
                theFolderBrowser.RootFolder = System.Environment.SpecialFolder.Desktop
                ' Default theFolderBrowserDialog object's SelectedPath property to the path to the Desktop folder.
                theFolderBrowser.SelectedPath = My.Computer.FileSystem.SpecialDirectories.Desktop
                ' If the user clicks theFolderBrowser's OK button..
                If theFolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ' Set the FolderChoiceTextBox's Text to theFolderBrowserDialog's
                    '    SelectedPath property.
                    'Received.Text = theFolderBrowser.SelectedPath'
                ' addera datum. klockslag till Pnamn    Pnamn_datumtid
    
                a = System.DateTime.Now.ToString("yyyy.MM.dd_HH:mm:ss")
                ' Pnamn = Form6.TextBox1.Text + "_" + a
                Pnamn = Form6.TextBox1.Text
                fpath1 = theFolderBrowser.SelectedPath + "\" + Pnamn + ".txt"

     FileOpen(2, fpath1, OpenMode.Append, OpenAccess.Write) 'save label file


    developer of embedded apps using VB as complement

    Friday, December 8, 2017 12:21 PM

All replies

  • This was my error, a subtle thing I did notice at first. Problem solved.

    developer of embedded apps using VB as complement

    Friday, December 8, 2017 12:51 PM
  • Yes, 

    I tried your code, it was working correct probably that the error is somewhere else. 

    Nevertheless, set in top of your code Option Strict On and start using the real VB string connector operator & instead of the+. 

    Also get rid of that old file handling. The IO.File class is so easy to use that you make it yourself only difficult.

    https://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx


    Success
    Cor

    Friday, December 8, 2017 1:00 PM
  • Hi zechzria12,

    Glad to hear this issue has been solved by yourself. Thanks for your sharing, I will introduce this experience to other forum users who face the same condition. Please mark your reply to close this case.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 11, 2017 1:29 AM
    Moderator