--- Do you have any idea how to create a file at all, yet?
no i dont have knowledge of it.
i have searched for file creation examples over net,
i have this code
Dim file As System.IO.FileStream
file = System.IO.file.Create("c:\test.txt")
but it is giving error in Dim statement as compiler error, user -defined type not defined.
this error might be due to missing referene. but i couldnt figure out which one is missing.
thanq
The reason for the error is in Visual Basic .NET most everything is an object and thus an Instance must be made of said object. Using the NEW keywork you can accomplish this task.
the statement:
- Dim file As System.IO.FileStream
does not work
however:
- Dim file As NEW System.IO.FileStream (<path>, <mode>)
does work
also it could have written as
- Dim file as System.IO.FileStream = System.File.Create("c:\test.txt")
I also noticed you used the word "file" as your file stream. file is a class of the namespace system.IO, I find it bad practice to use class names as variable names, even if the compiler lets you. The code below is an example of how to write a file with a few lines of text in it.
- ' Create the File stream for the ability to read and write to a specified file
-
Dim NewFile As New IO.FileStream("C:\somefile.txt", IO.FileMode.Create)
-
-
' Create a writer object, and have it use the stream created above
-
Dim writer As New IO.StreamWriter(NewFile)
-
-
' Write the file
-
writer.WriteLine("Hello Filesystem World!!!")
-
writer.WriteLine("This is my first text document written with Visual Basic!")
-
-
' VERY IMPORTANT: Close the file
-
writer.Close()
You question was to create a custom file extention, this is done byt simply changeing the file extention on creation
Dim NewFile As New IO.FileStream("C:\somefile.xyz", IO.FileMode.Create)
or
Dim NewFile As New IO.FileStream("C:\somefile.flob", IO.FileMode.Create)
keep in mind that the contents of the file are what you write to them, if you write "Happy birthday susie" and saved it as susie.jpeg extension. you will confuse any image reading software and if opened in notepad will read "Happy birthday susie"
there are encoding formats built into the .NET framwork (i.e. Unicode UTF-32, Unicode UTF-16, Unicode UTF-8, ASCII, and ANSI/ISO) but that is for a different question.
I hope this information helps you, good luck and happy coding
I do apologize for the length, I felt it adaquate to answer your question
Cyberdaemon
EDIT: When I read your original post I though you said using Visual Studio 2003...this is .NET suff. Most of the information still applies. I do apologize for the mistake.