Solved

files c#

Posted on 2012-04-10
2
170 Views
Last Modified: 2012-04-18
File is not the write context in c# what would be the syntax
 file.Open(1, Server.MapPath("\DBP.txt"), OpenMode.Input, OpenAccess.Read, OpenShare.Shared);

 File.close(1);
0
Comment
Question by:Seven price
[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
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 210 total points
ID: 37830891
Even in VB, FileOpen is not the recommended way to work. You will have to learn to work with streams.

There are many streams in .NET (FileStream, StreamReader, StreamWriter, StringWriter, StringReader, binary streams, XML streams), you might need to find the one that suits you the best. And in some situations, they need to be used in combination.

The one that is used most often to read text files is the StreamReader:

VB
Dim yourFile As New IO.StreamReader("\DBP.txt")
Dim line As String
line = yourFile.ReadLine

Open in new window

C#
System.IO.StreamReader yourFile = new System.IO.StreamReader("\\DBP.txt");
string line;
line = yourFile.ReadLine();

Open in new window

No need to pass the other parameters, the role of the StreamReader being to read files, it opens by default with those conditions. That is why .NET has many streams, each one is specialized, so they are easier to open and to work with than the old ways.

ReadLine is one of the many methods you can use to read with a StreamReader, so explorer the other ones. Note that the norion of EOF (EndOfFile) has been replaced by the EndOfStream property of the Stream.

And also be aware than in C#, the backslash has a special meaning, so you need to use a double one where you used only one in VB.
0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 37862998
tks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

624 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