Results 1 to 5 of 5

Thread: [RESOLVED] I need help with the following code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    104

    Resolved [RESOLVED] I need help with the following code

    Hello Everyone:

    I am new in programming and I am using vb2005.

    This is what I have; I have created a project, where I allow the user to add a new record, when adding a new record they may have to included attachments, I have added an attachment button where I give the user a browse option to select any type of files and I am using the IO.Copy feature
    HTML Code:
    System.IO.File.Copy(s, Destination & Path.GetFileName(s), True)
    So far this is working great; I have created a folder in my local drive where the file gets copied "C:\Program Files\Support Desk\Attachments\". When the user adds an attachment I have added a "Linklavel" where displays the File name;example "Picture.jpeg, textdoc.doc, testtxt.txt".

    Here is where I am having problems; under the click event of the "Linklavel" I have added the following code:
    Code:
    'Declare those variables!
            Dim sFileName As String = "C:\program files\Support Desk\Attachments\"
            Dim myFileStream As New System.IO.FileStream(sFileName, _
                FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
    
            'Create the stream writer
            Dim myWriter As New System.IO.StreamWriter(myFileStream)
    
            'Write in what is in the text box
            myWriter.WriteLine(LinkEditAttach1.Text)
    
            'Flush before we close
            myWriter.Flush()
    
            'Close everything
            myWriter.Close()
            myFileStream.Close()
    
            'Clear the text
            LinkEditAttach1.Text = ""
    In my project I have give the option to edit an added record, where the user can make notations and view the attachments if they have to.
    I would like to when they click on one of the file names, to open the file for them to view it, or save it if they want to.

    The code above is braking under the following line of code:
    Code:
    Dim myFileStream As New System.IO.FileStream(sFileName, _
                FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
    It tells me that path "C:\program files\Support Desk\Attachments\" doesn't exist.

    What am I doing wrong. is the code correct?
    Thanks in advance.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: I need help with the following code

    sFileName needs to be the full path to the file. Ex: "C:\program files\Support Desk\Attachments\Picture.jpg". You can't open a file stream on the directory.

    As far as doing all this (opening a file) try this:

    Code:
    Process.Start("Path to file here")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    104

    Re: I need help with the following code

    Hello ForunAccount :-)

    Thank you so much for your quick response:

    So, should I do the following?
    Code:
    Dim sFileName As String = "C:\program files\Support Desk\Attachments\" & LinkEditAttach1.Text
    
     Dim myFileStream As New System.IO.FileStream(sFileName, _
                FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
    Process.Start("sFileName")
    I am new in programming :-)

    Thanks,

    BK

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: I need help with the following code

    Just this:
    Code:
    Dim sFileName As String = "C:\program files\Support Desk\Attachments\" & LinkEditAttach1.Text
    
    Process.Start(sFileName)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    104

    Re: I need help with the following code

    Thank you so much for your help and it was very helpful

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