Click here to Skip to main content
14,865,310 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function that write into text file,the function run without any error, but when i check the text i see that nothing happens, the file is empty.

the Problem appear when i want to write to partition "C",i tried on "D" it's work, but why ?

Sub WritePass(ByVal _FilePath As String, ByVal _Pass As String)
            If System.IO.File.Exists(_FilePath) = True Then

                Dim objWriter As New System.IO.StreamWriter(_FilePath)

                MsgBox("Text written to file")


                MsgBox("File Does Not Exist")

            End If
        Catch ex As Exception
        End Try

    End Sub
Updated 26-Aug-13 21:33pm
TrushnaK 27-Aug-13 3:45am
are you have permission on c drive...

That is because partition "C" has some Security.

You can't read, write to a file without permission.
Ahmad Al Halabi 27-Aug-13 3:50am
the file created, but the value not written
That means creation permission is there, but not the write permission.

Can you debug and see what happens after the below line executes?

Ahmad Al Halabi 27-Aug-13 4:05am
I Found the Problem, I am creating stream reader before this function, and i mess to close the reader, because that i can't write any thing ooops
Oh great work. :)

Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Could it be possible you are trying to write at the root of your C: drive ?
On modern MS OS's, access to the system drive's root is restricted.

May we know the value of your _FilePath at the time you are calling your method ?
Ahmad Al Halabi 27-Aug-13 3:43am
PassPath = "C:\Program Files\Sana Computers\SanaPassword.txt"
phil.o 27-Aug-13 4:01am
You should not write to the Program Files directory.
Better write to Prgram Data if you want to avoid this type of issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900