472,353 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Random Access Files in C#

Hello,

Is there a simple way to read a random access file that has been created
with VB6 using direct writing to disk of Type....End Type structures ?
I have not found this possibility in C#.

Is it possible to map directly a buffer (read from a stream) to a
Structure in memory ?
If yes, how to do this ?
If no, any hint to read/access/write random access files ?
I would appreciate any advice or comment.
Regards,
Cybertof.
Nov 15 '05 #1
3 9995
Cybertof,

This is not supported in .NET. If you want to do something like this in
..NET, then you will find it easiest if you use unsafe code (so that you may
access pointers in memory) as well as calls to the appropriate APIs to
create open the file and write the contents from memory.

If you don't want to go so far, you could declare your structures as if
you were marshaling them across the unmanaged/managed boundary. Then, you
could use the static SizeOf method on the Marshal class to figure out how
many bytes to read from the underlying stream. Once you have those bytes,
you can copy them to unmanaged memory, and then call the static
PtrToStructure method on the Marshal class to read from the unmanaged memory
to your structure. Of course, this will be less performant than the first
option, but it would not require the use of unsafe code.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
Hello,

Is there a simple way to read a random access file that has been created
with VB6 using direct writing to disk of Type....End Type structures ?
I have not found this possibility in C#.

Is it possible to map directly a buffer (read from a stream) to a
Structure in memory ?
If yes, how to do this ?
If no, any hint to read/access/write random access files ?
I would appreciate any advice or comment.
Regards,
Cybertof.

Nov 15 '05 #2
Nicholas,

Thanks for these first elements.
I would be interested in knowing a little more about your 2 options.

Do you have any sample code / info regarding
- using unsafe code (to access pointers)
- marshaling structure regarding unmanaged/managed boundary.
(btw.....what does 'marshaling' means ?)

When you say "as well as calls to the appropriate APIS to
create/open/write the contents from memory".
Do you mean than with mixing unsage-code and safe-code it is not
possible to use at the same time the .net native streams to
create/write/read files ?
Cybertof.
In article <#d*************@tk2msftngp13.phx.gbl>,
ni**************@exisconsulting.com says...
Cybertof,

This is not supported in .NET. If you want to do something like this in
.NET, then you will find it easiest if you use unsafe code (so that you may
access pointers in memory) as well as calls to the appropriate APIs to
create open the file and write the contents from memory.

If you don't want to go so far, you could declare your structures as if
you were marshaling them across the unmanaged/managed boundary. Then, you
could use the static SizeOf method on the Marshal class to figure out how
many bytes to read from the underlying stream. Once you have those bytes,
you can copy them to unmanaged memory, and then call the static
PtrToStructure method on the Marshal class to read from the unmanaged memory
to your structure. Of course, this will be less performant than the first
option, but it would not require the use of unsafe code.

Hope this helps.

Nov 15 '05 #3
Nicholas ?......

If you read me if you could put a short reply :=)

Thanks,
Cybertof.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Oin Zea | last post by:
Is it possible for to program to access a random file at the same time and perform actions like create a new record?
9
by: greeningster | last post by:
I have written an application in Visual C++ for a customer but it seems to crash randomly. Could anyone give me any help on how I could track...
1
by: Patrick | last post by:
Hi, This post is the 'sequel' ;) of the "Data Oriented vs Object Oriented Design" post, but it can be read and treated apart from that one. I...
5
by: Raterus | last post by:
I'm just throwing this error out for my sanity, I've seen posts about this, but never solutions. I'm using VS.NET 2003, Framework 1.1, and I'm...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1,...
13
by: Stuart | last post by:
I have converted a VB6 app to VB.NET. It's function is to generate reports from a Random Access file but the .NET version is pathetically slow...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte...
39
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have...
5
by: Peter | last post by:
Hi I will use a Random Access File in dotnet/csharp. The file is created with Visual Basic 6 (VB6). My Problem is to find out the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.