Streamwriter not creating file -- sometimes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Selden McCabe

    #1

    Streamwriter not creating file -- sometimes

    I'm using the following code to write some text to a file:

    objWriter = New StreamWriter(Fu llPath, True, System.Text.Enc oding.ASCII)
    For nRow = 1 To sData.Length - 1
    objWriter.Write Line(sData(nRow ))
    Next nRow
    objWriter.Flush ()
    objWriter.Close ()

    When I run this in the IDE, it works. When I compile it and run the EXE, it
    doesn't give any errors, but it doesn't create the file either. I've tried
    putting a message box in the loop, and the data is acutally there. I've put
    this in a try/catch block, but it doesn't catch any error.

    I've tried creating a setup package, building it, then running the setup.
    Same behavior.

    I've also tried just objWriter = New StreamWriter(Fu llPath), same behavior.

    What am I doing wrong? Any ideas or suggestions at all would be
    appreciated!
    Thanks,
    ---Selden McCabe






  • Selden McCabe

    #2
    Re: Streamwriter not creating file -- sometimes

    Here's some additional information:

    The code with the streamwriter was in a separate Class project which was
    added to my solution. So this code was running in a DLL separate from the
    main executable.

    When I copied the code from this class into the form's button_click event,
    it worked.

    So, for some reason, having the code in a separate DLL causes the problem.

    Any ideas why?

    Thanks again,
    ---Selden


    Comment

    • Selden McCabe

      #3
      Re: Streamwriter not creating file -- sometimes

      Here's some additional information:

      The code with the streamwriter was in a separate Class project which was
      added to my solution. So this code was running in a DLL separate from the
      main executable.

      When I copied the code from this class into the form's button_click event,
      it worked.

      So, for some reason, having the code in a separate DLL causes the problem.

      Any ideas why?

      Thanks again,
      ---Selden


      Comment

      • Chris Dunaway

        #4
        Re: Streamwriter not creating file -- sometimes

        I'd say double check the value of the FullPath variable and make sure
        the file is being written where you think it is.

        How is the FullPath variable being constructed?

        Comment

        • Chris Dunaway

          #5
          Re: Streamwriter not creating file -- sometimes

          I'd say double check the value of the FullPath variable and make sure
          the file is being written where you think it is.

          How is the FullPath variable being constructed?

          Comment

          • Crouchie1998

            #6
            Re: Streamwriter not creating file -- sometimes

            Are you referencing the DLL correctly?

            Is it necessary to have a streamwriter in a seperate DLL?

            Comment

            • Peter Huang [MSFT]

              #7
              Re: Streamwriter not creating file -- sometimes

              Hi Selden,

              Have you tried Chris's suggestion?
              I agree with Chris's suggestion that the FullPath is not the destination
              dir you means.
              To verify it, you may try to use a Console.WriteLi ne(FullPath) to write the
              string out to confirm it.

              Best regards,

              Peter Huang
              Microsoft Online Partner Support

              Get Secure! - www.microsoft.com/security
              This posting is provided "AS IS" with no warranties, and confers no rights.

              Comment

              • Michael Schutte

                #8
                RE: Streamwriter not creating file -- sometimes

                It's not creating file because of your second parameter. That parameter you have set to true, which is "Append" to existing file.

                If the file doesn't exist, it's not going to create it. You need to first check to see if it exist. If it exists, then the second parameter needs to be TRUE otherwise set it for FALSE!

                From http://www.developmentnow.com/g/38_2...-sometimes.htm

                Posted via DevelopmentNow. com Groups
                DevelopmentNow is an award-winning creative software development agency integrating mobile, web, hardware, mixed reality, and emerging technology.

                Comment

                Working...