Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

beginer in visual c# need direction

Posted on 2007-11-14
8
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 1

Accepted Solution

by:
felixyo earned 2000 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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
 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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