473,480 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

creating a file of particular extension

86 New Member
i am using ms access 2003, vb6.

i want to create a file of extension ".gms"(if not, any particular extension)
how can i do this?

also after creating it, i want to open the file with default viewer(default opening application for .gms extenision files).

how can i do this?

thanq
Jul 19 '07 #1
5 3094
Killer42
8,435 Recognized Expert Expert
Do you have any idea how to create a file at all, yet?
Jul 19 '07 #2
ravindarjobs
86 New Member
--- 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
Jul 19 '07 #3
cyberdaemon
38 New Member
--- 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:
Expand|Select|Wrap|Line Numbers
  1. Dim file As System.IO.FileStream
does not work

however:

Expand|Select|Wrap|Line Numbers
  1. Dim file As NEW System.IO.FileStream (<path>, <mode>) 
does work
also it could have written as
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1. ' Create the File stream for the ability to read and write to a specified file
  2.         Dim NewFile As New IO.FileStream("C:\somefile.txt", IO.FileMode.Create)
  3.  
  4.         ' Create a writer object,  and have it use the stream created above
  5.         Dim writer As New IO.StreamWriter(NewFile)
  6.  
  7.         ' Write the file
  8.         writer.WriteLine("Hello Filesystem World!!!")
  9.         writer.WriteLine("This is my first text document written with Visual Basic!")
  10.  
  11.         ' VERY IMPORTANT:  Close the file
  12.         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.
Jul 19 '07 #4
cyberdaemon
38 New Member
General file access in VB6:

open "C:\somefile.txt" for output as #1

print #1, "Hello FileSystem World!!"

close #1

everything else still applies concerning the file extension

Cyberdaemon
Jul 19 '07 #5
ravindarjobs
86 New Member
thanq frnds.

a similar question.
suppose i have a word file a.doc file. when i click the button the file should be opened with the default viewer(here the default viewer is ms word),
and the same way how to open a partuicular file with default viewer of its?
Jul 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9697
by: PK | last post by:
Hello, I am looking for help on the following. I'm trying to create a custom browser toolbar button that will do a few things. One that I'm trying to do at the moment is just simply return the...
2
1486
by: JeffFinnan | last post by:
Is there a way Netscape 4.x can be forced to select a particular file extension other than the default .html? =============================== <form name=form1> <input type=file name="fileN">...
7
1484
by: Sam Carleton | last post by:
I am trying to figure out how to get VS.Net and IIS6 to work together... I am working in domain nowhere.local. I have a W2K3 server named server1.nowhere.local that is running IIS6. I want it...
2
1661
by: chuckdfoster | last post by:
I have a page that users upload files. Is there a way to restrict the file types that they can upload? thanks, -- Chuck Foster Programmer Analyst Eclipsys Corporation - St. Vincent Health...
6
2852
by: William F. Zachmann | last post by:
We've got a project going that involves moving an old web site with a massive dll written in C++ that produces most of the output from a SQL 7.0 data base on NT4 onto IIS on Windows 2003 Server...
0
2528
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a...
10
3740
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
5
3111
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could...
36
5315
by: Don | last post by:
I wrote an app that alerts a user who attempts to open a file that the file is currently in use. It works fine except when the file is opened by Notepad. If a text file is opened, most computers...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.