Solved

beginer in visual c# need direction

Posted on 2007-11-14
8
374 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

867 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

12 Experts available now in Live!

Get 1:1 Help Now