Solved

beginer in visual c# need direction

Posted on 2007-11-14
8
373 Views
Last Modified: 2013-12-17
ok .. so i have this software to build and i need direction with visual studio 2008... i have visual C# as the language ...  anyhow i want to build a sol'n ... the software should ask which file to locate in the which directory and then read the file which is .dbf .csv and sql format  ... this is the first step that i need to get ... anyhow i am new to visual studio and i am in need of direction of what classes to make and how to link them ... also i need code as well ... like for example the sol'n file in the visual studio so that i can build on top of it.
0
Comment
Question by:da_emerson
  • 4
  • 4
8 Comments
 
LVL 1

Accepted Solution

by:
felixyo earned 500 total points
ID: 20293351
You can use the OpenFileDialog class .
If you create a windows application ,here is the way you can do that in the click event of a button .
using System.IO ; 

private void button1_Click(object sender, System.EventArgs e)

            {

                Stream myStream = null;

                OpenFileDialog openFileDialog1 = new OpenFileDialog();

             

                openFileDialog1.InitialDirectory = "c:\\" ;

                openFileDialog1.Filter = "database files (*.dbf)|*.dbf|comma-separated value files (*.csv)|*.csv|sql files (*.sql)|*.sql" ;

                openFileDialog1.FilterIndex = 2 ;

                openFileDialog1.RestoreDirectory = true ;
 

                if(openFileDialog1.ShowDialog() == DialogResult.OK)

                {

                    try

                    {

                        if ((myStream = openFileDialog1.OpenFile()) != null)

                        {

                            using (myStream)

                            {

                                // Insert code to read the stream here.

                                

                            }

                        }

                    }

                    catch (Exception ex)

                    {

                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);

                    }

                }

            }

Open in new window

0
 

Author Comment

by:da_emerson
ID: 20297798
first of all thanks a lot of helping me out .... i have read the code and its amazing work ... so i did open an windows application and i have placed a button for opening a file ... so you press the file and it will ask you for the location of the file or folder in c drive so that it can open the .csv or .dbf or sql file ... and in that click event i have placed the code that you have provided ) ... and now i have to start to go over openfiledialog to read a little about that ... i thought that i should use ADO to read the file into the dataset and then read the data from there as an ADO object ... anyhow can you tell me please what i have to look for in the streamreader ??? opening a new streamreader object that will hold the object and i can connect to??
0
 
LVL 1

Expert Comment

by:felixyo
ID: 20299366
Hello . You don´t need to use an ADO object because this is not a database , they are files and besides the technology for accesing to databases in .Net it´s called ADO.NET .

In this case I tell you how to use the FileStream object for reading and accesing to the file .
I show you that in this code :



private void button1_Click(object sender, System.EventArgs e)

            {

                

                FileStream myStream = null;

                OpenFileDialog openFileDialog1 = new OpenFileDialog();

             

                openFileDialog1.InitialDirectory = "c:\\" ;

                openFileDialog1.Filter = "database files (*.dbf)|*.dbf|comma-separated value files (*.csv)|*.csv|sql files (*.sql)|*.sql" ;

                openFileDialog1.FilterIndex = 2 ;

                openFileDialog1.RestoreDirectory = true ;
 

                if(openFileDialog1.ShowDialog() == DialogResult.OK)

                {

                    try

                    {

                        if ((myStream = (FileStream)openFileDialog1.OpenFile()) != null)

                        {

                            using (myStream)

                            {

                                byte[] b = new byte[1024];

                                UTF8Encoding temp = new UTF8Encoding(true); //Represent characters Unicode UTF-8 encoding

                                while (myStream.Read(b, 0, b.Length) > 0) //The file is read into an array of bytes

                                {

                                    textBox1.Text = temp.GetString(b); //You can show the file contents into a control like a textbox , TextBox1 must be multiline= true

                                 

                                }

                              

                               
 

                            }

                        }

                    }

                    catch (Exception ex)

                    {

                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);

                    }

                }

            }

Open in new window

0
 

Author Comment

by:da_emerson
ID: 20304997
i can see that there is byte array and spits out the data in the textbox ... this is excellent ... but now i need to build on this and go forward with the project ... i need to read from multiple files of the same type which are the dbf and csv and sql files. also i need to store them according to their tags .. each file has a type for them self ... can you please tell what i need to do now in the mystream reader ?

;-)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:da_emerson
ID: 20313060
i can see the data in the textbox with no problem but i want to make it so that it reads from multiple files and puts all the data into one file sort of speak ... can u show me how i can do this please ... also i have this other type of file which has the tags that explains the data on the other files ... its like the data in the files are all numbers and some information regarding the data ... in the other file there exists only units and tags for those numbers ... and then i have to use my engine to graph those data ... I have no idea what to do here after reading from a single file to multiple files so that it can graph multiple units together ... please help me out here ... please ... thnx
0
 
LVL 1

Expert Comment

by:felixyo
ID: 20313871
Hello da_emerson , with the solution I am giving here I am giving you the answer to your question that was how to open a file o different extensions and read from it . You can accept this answer if that is useful to you .

From your comment I can see , After this you want to do something with this data , you want to store it in some way and sort it and read that data and make some graphs with it  , all these things are subject for another question . If you want you can accept my answer and place another question explaining specifically what you want to do with that data and I''ll be glad to help you .

regards .
0
 

Author Comment

by:da_emerson
ID: 20313922
hi felixyo ... i just wanted to say that i do love the sol'n that you have ... so i am going to post another question ... and thanks so so so much ...

;-)
0
 
LVL 1

Expert Comment

by:felixyo
ID: 20315907
I am glad it was an useful solution to your question .
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now