|
There is some length limit for stream, it won't take all of your machine's memory. I think it was some 512 MB on 64bit systems.
|
|
|
|
|
Thanks everyone. I will give this a try.
Sharon
|
|
|
|
|
Based on Luc Pattyn's answer I found the following.
Trouble with the Large Object Heap[^]
It claims the problem does not exist on large memory platforms although that would seem unlikely to me (more likely that it just takes longer to show up.)
However if that is the problem then based on your original code snippet then the solution would be to use a fixed buffer rather than allocating it each time. This would require redoing to the code to allow for reading files that are larger than the allocated buffer.
The solution is simple if you are doing sequential processing but more complicated with a thread processing. In that case you would need to use an object pool where the pool contained buffers.
|
|
|
|
|
Hi!
I have a file which contains this information:
A
B
C
D
E
F
I iterate over all lines in the file. When I reach B, I want to store the location of C in a variable.
When I later hit EndOfStream I would like to set the StreamReader's pointer with Seek() method back to C and continue reading until I hit EndOfStream.
Here is where I stumble over problems. When I store the StremReaders.BaseStream.Position in a long variable, it always store 16.
When later using Seek() method with the stored location I don't read C just null.
I don't know if EndOfStream has something to do with it. I also tried to use DiscardBufferedData() method, but I just flags the EndOfStream property.
This might looks like to be a very weird functionality but it's a small part of a functionality I need.
I just need to know how to set the position of a StreamReader instance somewhere in the file and continue read from it.
Here is my code:
static void Main(string[] args)
{
string filePath = @"C:\File1.txt";
StreamReader reader = new StreamReader(filePath);
long position = 0;
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (line == "B")
{
position = reader.BaseStream.Position;
}
Console.WriteLine(line);
}
reader.BaseStream.Seek(position, SeekOrigin.Begin);
Console.WriteLine(reader.ReadLine());
reader.Close();
}
|
|
|
|
|
The reason it returns 16 is that that is the length of the file...
BaseStream.Position does not do what you want - you want to use the Seek method combined with the position of the character in the stream. So, there is good news and bad news:
Good news: The position is stored in StreamReader.charPos, and does exactly what you want.
Bad news: It's a private variable.
So, getting it and using it is a bit dodgy - you can do it via reflection, but then your code will rely on an undocumented feature, which could disappear at any time. If you want to go that route, there is an extension method which does it all for you here: http://www.daniweb.com/software-development/csharp/threads/35078/page2[^] The code is about 3/4 of the way down.
Not a good idea, to my mind. Instead, I would use a Binary Reader, and read the data directly, processing the lines for myself:
BinaryReader br = new BinaryReader(File.OpenRead(@"D:\Temp\MyList.txt"));
int recordLength = 16;
for (int i = 0; i < 10; i++)
{
Console.WriteLine("{0}: {1} = {2}", i, br.BaseStream.Position, (char) br.ReadByte());
}
Console.WriteLine();
Gives:
0: 0 = A
1: 1 = B
2: 2 = C
3: 3 = D
4: 4 = E
5: 5 = F
6: 6 = G
7: 7 = H
8: 8 = I
9: 9 = U
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I appears that StreamReader reads more than you expect and buffers it -- hence the Position of the Stream isn't where you think it is.
I suggest using a Stream rather than StreamReader.
|
|
|
|
|
Hello Everyone
I begin to develop an application using C #, but I can not handle the DataGridView has actually I manage to display data from a table but after posting I need to recover the contained of a cell but I can not !! in fact I want to use the datagrid to manage user profile (add, edit and delete).
pleaaaaaaase i need your helppp !!!!!
|
|
|
|
|
I need to recover the contained of a cell but I can not
This doesn't make sense. Did you mean 'content'? The DGV allows you to access cells directly: myDGV.Cells[2, 6].Value.
|
|
|
|
|
yes i mean the content of the cell!! i tried your methode (dataGridView1.Cells [1, 1].value;) but "Cells" does not exist (an assembly reference is messing) :/ i tried also ( oConnexion.Open();
reader = command.ExecuteReader();
DataTable DataTable1 = new DataTable();
DataTable1.Load(reader);
foreach (DataRow row in DataTable1.Rows)
{
foreach (DataColumn column in DataTable1.Columns)
{
MessageBox.Show(column.DataType.ToString());
MessageBox.Show(column.DefaultValue.ToString());
MessageBox.Show(column.ToString());
column.DataType.ToString();
MessageBox.Show(column.Table.Rows[0].ToString());
MessageBox.Show(column.ExtendedProperties.ToString());
textBox1.AppendText(row[column].ToString());
textBox1.AppendText((string)(row[column]));
textBox1.AppendText(" | ");
}
textBox1.AppendText("\r\n--------------\r\n");
}
})
but it return the whole column not only one cell :/
|
|
|
|
|
Is this the WinForms DataGridView?
Turns out I was remembering something else, you can't index it like that, you have to do myDgv.Rows[2].Cells[3].Value.
And, uh, of course that example gets the whole column because it loops over all rows! Programming isn't something you should just hack around and hope something works (well, no discipline is like that really) – if you can't read that snippet and work out that it will get a table from a data source and then construct text output for the whole table, you need to go back to basics and make sure you've got the language structures (loops and so on) and the classes (data and UI) straight in your head.
|
|
|
|
|
BobJanova wrote: Programming isn't something you should just hack around and hope something works
I actually know a couple of well respected developers that have mastered the ability to "just hack around". A sort of meta-p.o.c. type development. The things that work correctly, stick, while the things that do not, changes until it works correctly. QA/QC would be obsolete if everything worked the first time -which is realistically known as inconceivable. The type previously described is one way to make it to QA. I take a different approach personally but, it really doesn't matter as long as the code functions as required, is maintainable, and is complete in the allotted time. What are "best practices" anyways other than socially acceptable opinions? Don't get me wrong, I do tend to agree with development best practices but when it comes down to it, it is merely an officially accepted opinion on how things should be.
|
|
|
|
|
DataGridView is filth and shouldn't be used for "real work".
missoby wrote: I want to ... manage user profile
Write a proper Form for doing that -- your users will thank you.
|
|
|
|
|
Hi
How load image with dat format in csharp?
|
|
|
|
|
|
A "DAT" file can be anything. It's a generic extension that just means "Data". You have to examine the file contents directly if you want to figure out what is in the file.
You can try to load the file with the Image.FromFile class, but if it isn't a image standard that's known, it's not going to work. Then you'll haev to use your eye balls and examine the contents byte-by-byte to figure out what kind of file it is.
|
|
|
|
|
hi, i am interested in making a simple software to download data from usb port from device such as a finger print reader, or those finger print software.
anyone know the basic and can point me in the right direction to read the relevant required programming class in vs.net c#?
|
|
|
|
|
|
There should be an SDK for such a device. Try to get it from the manufacturer. Ideally, the SDK has an example program in a .NET language, but it could be that you have to figure it out from plain C code.
If no SDK is available, things become complicated, and I cannot tell you how to do that.
|
|
|
|
|
You don't talk to the "port" like you do a serial or parallel port. Look at the name: USB. Remember what it stands for?? Universal Serial BUS.
It's a bus, not a port. It's no different than try to talk to the expansion slots inside your computer. You can't. You talk to the devices plugged into them, not the slots themselves.
The best option you have is to get with the manufacturer of the device and get the SDK for it. If there isn't one, your project just got a whole lot more complicated.
|
|
|
|
|
I am working on a series of projects that will share several libraries/assembies. Some projects will be part of shared solutions, some will not.
I am looking at the best way to setup my SCC server (TFS 2010). My current thought is have a shared Assemblies folder that each project has a branch of. The problem is after a while (months, years, ect.) that Assemblies folder will get pretty big, as well as contain several versions of DLLs.
How do you guys go about doing this? I've seen suggestions to have each project have it own Assemblies folder, but I would really like SCC to have the Assemblies folder out of project level as well.
Any ideas? P.S. Sorry if it doesn't make too much sense, I am over tired and took a sleeping pill for good measure.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I don't know anything about SCC, but it sounds dreadful.
Are these third-party DLLs? If so, I agree with keeping them together.
|
|
|
|
|
Have a separate project in source control that contains nothing but common dependencies, and include that in all the other projects (either by a direct reference mechanism if TFS supports that, or just by checking it out adjacent and referencing things by ../ paths).
|
|
|
|
|
Expert Coming wrote: Any ideas?
Depends on what you mean by "projects".
I work on 'deliverables'. Each of those represents a discrete business grouping of functionality which can and does include groupings like the following
1. One or more dlls.
2. A single executable (console or windows service)
3. Several executables.
When each is delivered it is labeled in source control (vendor does not matter), built from that label, and only that label, and then delivered as a single module/release.
Each deliverable is independent from the others and the expectation is that each can have their own project timeline, etc.
Since the deliveries are independent each deliverable MUST be contained within itself. That requirement means that if a single deliverable is using some sort of "shared" functionality (such as a library dll) that that shared functionality MUST be represented as its own deliverable.
This is true whether I produce the shared code or if I am using a 3rd party library.
That is the only way to insure that the code is written to match what it will be delivered with and tested against the same.
|
|
|
|
|
how to convert file bmp to array binary. aray with values 0 and 1
lieu_li
|
|
|
|
|