473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Save File from a Win Form application

I'm working on a WinForm application, and recently was informed that I need
to create an "Export" function for the data (stored in SQL Server), in a
specific (TXT, tab delimited) format.
I'd like to figure out a way to bring up the "Open or Save" dialog similar
to what we see on Web Pages, but with a minimal amount of coding (especially
considering this isn't a Web application), but would then allow me to create
a TXT file and either open it (in whatever they have set as the default
application for TXT files, like Notepad) or save it (in which case they'd
get the standard SaveAs dialog)
Is there an easy way to do this in .NET?
Thanks!
Nov 21 '05 #1
2 3084
Start a new Windows application

Add two buttons to it (Button1 & Button2 respectively)

Double-click an 'OpenFileDialog' control (its added to the project)

Double-click an 'SaveFileDialog' control (its added to the project)

Double-click Button1 & paste in the following code:

With OpenFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strOpenFilename = .FileName
Else
Exit Sub
End If
End With
' Do stuff here

-----------------------

Double-click Button2 & paste in the following code:

With SaveFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strSaveFilename = .FileName
Else
Exit Sub
End If
End With
' Save tab delimited data here

--------------------------------------------------------

This is the code behind Button2, but with a tab delimited section at the end:

With SaveFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strSaveFilename = .FileName
Else
Exit Sub
End If
End With
' Save tab delimited data here
' Example:
Dim sw As New IO.StreamWriter(strSaveFilename)
sw.WriteLine("Some Data" & ControlChars.Tab & "Some More Data...")
sw.Flush()
sw.Close()

------------------------------------------

I hope the above helps

"Scott M. Lyon" wrote:
I'm working on a WinForm application, and recently was informed that I need
to create an "Export" function for the data (stored in SQL Server), in a
specific (TXT, tab delimited) format.
I'd like to figure out a way to bring up the "Open or Save" dialog similar
to what we see on Web Pages, but with a minimal amount of coding (especially
considering this isn't a Web application), but would then allow me to create
a TXT file and either open it (in whatever they have set as the default
application for TXT files, like Notepad) or save it (in which case they'd
get the standard SaveAs dialog)
Is there an easy way to do this in .NET?
Thanks!

Nov 21 '05 #2
That worked great! Thanks a million, man!
-Scott

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Start a new Windows application

Add two buttons to it (Button1 & Button2 respectively)

Double-click an 'OpenFileDialog' control (its added to the project)

Double-click an 'SaveFileDialog' control (its added to the project)

Double-click Button1 & paste in the following code:

With OpenFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strOpenFilename = .FileName
Else
Exit Sub
End If
End With
' Do stuff here

-----------------------

Double-click Button2 & paste in the following code:

With SaveFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strSaveFilename = .FileName
Else
Exit Sub
End If
End With
' Save tab delimited data here

--------------------------------------------------------

This is the code behind Button2, but with a tab delimited section at the end:
With SaveFileDialog1
.DefaultExt = "txt"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 0
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog = DialogResult.OK Then
strSaveFilename = .FileName
Else
Exit Sub
End If
End With
' Save tab delimited data here
' Example:
Dim sw As New IO.StreamWriter(strSaveFilename)
sw.WriteLine("Some Data" & ControlChars.Tab & "Some More Data...")
sw.Flush()
sw.Close()

------------------------------------------

I hope the above helps

"Scott M. Lyon" wrote:
I'm working on a WinForm application, and recently was informed that I need to create an "Export" function for the data (stored in SQL Server), in a
specific (TXT, tab delimited) format.
I'd like to figure out a way to bring up the "Open or Save" dialog similar to what we see on Web Pages, but with a minimal amount of coding (especially considering this isn't a Web application), but would then allow me to create a TXT file and either open it (in whatever they have set as the default
application for TXT files, like Notepad) or save it (in which case they'd get the standard SaveAs dialog)
Is there an easy way to do this in .NET?
Thanks!

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Aliza Klein | last post by:
I am new to ASP so please pardon me if this is crazy. I have data that I want to allow the user to be able to save in a format that will then enable the user to open the data in Excel. (I have...
4
by: sunilj20 | last post by:
Hello, I have a requirement wherein, a user clicks on a file name in an ASP.NET web application, and the file should automatically be downloaded (Without showing the "Open", "Save As") in the...
3
by: Stefano | last post by:
I've a form windows with a lot of textbox controls. How can I do if I have to save all text proprety of this controls in an external file, to reload them in future?
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
4
by: Richard Lewis Haggard | last post by:
I have an application that can't use the registry to save various user options and application settings. My first thought was to simply use an application configuration file but this approach seems...
4
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
1
by: rn5a | last post by:
When users submit a Form with a SQL query, the resultset is retrieved from a MS-Access database table which is then exported to an MS-Excel worksheet. After the records get exported to MS-Excel, I...
2
by: JPS | last post by:
We have a ASP.Net/SQL Server application that is used as a document management system. The documents are stored per project. The files are stored on a file server but we store the file name in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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
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...

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.